File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes How do I pass an array as an argument to a Constructor? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How do I pass an array as an argument to a Constructor?" Watch "How do I pass an array as an argument to a Constructor?" New topic
Author

How do I pass an array as an argument to a Constructor?

Colby Allen
Greenhorn

Joined: Nov 11, 2009
Posts: 9
Ok here is my situation. I have this array in my demo program ---> double[] badScores = {97.5, 66.7, 88.0, 101.0, 99.0 }; I need to pass this as an argument to my parametrized constructor. I know how to do it going down the line with user input. But this for some reason is throwing me for a loop since I am just given an array instead of having a user input the numbers.

Edit: *facepalm* Ok it never fails right after I post an issue I figure it out just like that.

Anyway for anyone searching for this issue here is how I did it.

Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30294
    
150

Colby Allen wrote:Edit: *facepalm* Ok it never fails right after I post an issue I figure it out just like that.

Anyway for anyone searching for this issue here is how I did it.

Thanks for posting the answer for others who have the same question!


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19670
    
  18

Just a hint: you can use System.arraycopy to do the copying for you. So instead of you can simply write This means: copy SIZE elements from s to scoreArray, starting at 0 for both s and scoreArray.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Colby Allen
Greenhorn

Joined: Nov 11, 2009
Posts: 9
Jeanne Boyarsky wrote:
Colby Allen wrote:Edit: *facepalm* Ok it never fails right after I post an issue I figure it out just like that.

Anyway for anyone searching for this issue here is how I did it.

Thanks for posting the answer for others who have the same question!


No problem. I hate a wasted post, so if somebody searches for this post then I want them to be able to find what they are looking for. Also this forum has helped me plenty, so I like to give back when I can.

Rob Prime wrote:Just a hint: you can use System.arraycopy to do the copying for you. So instead of you can simply write This means: copy SIZE elements from s to scoreArray, starting at 0 for both s and scoreArray.


Thanks for the tip! I will try to remember that in the future.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How do I pass an array as an argument to a Constructor?