Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Colby Allen
Greenhorn
Posts: 9
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
author & internet detective
Marshal
Posts: 33697
316
Eclipse IDE Java VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Rob Spoor
Sheriff
Pie
Posts: 20393
46
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Colby Allen
Greenhorn
Posts: 9
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic