Results 1 to 2 of 2
Thread: What does this Constructor Do ?
- 10-02-2010, 05:44 PM #1
What does this Constructor Do ?
Hi Guys
I have a bit of Java code and I'm trying to digest it and understand it.
Here is the code:
The first bit of code that I'm trying to get my head around is this bit of the randomise() method:Java Code:public class SimpleRandomCount extends RandomCount { /** * Constructor */ public SimpleRandomCount(int size) { super(size); } /** * Randomise the array */ protected void randomise() { Integer[] copy = new Integer[array().length]; // used to indicate if elements have been used boolean[] used = new boolean[array().length]; Arrays.fill(used,false); for (int index = 0; index < array().length; index++) { int randomIndex; do { randomIndex = randomIndex(); } while (used[randomIndex]); copy[index] = array()[randomIndex]; used[randomIndex] = true; } for (int index = 0; index < array().length; index++) { array()[index] = copy[index]; } } } // End of class SimpleRandomCount
What does the bottom line do and which array does it do it to ? cause there are two array (copy and used) initiated above that line !Java Code:Integer[] copy = new Integer[array().length]; // used to indicate if elements have been used boolean[] used = new boolean[array().length]; Arrays.fill(used,false);
I would greatly appreciate any help.
Thank You.>> What can be asserted without proof can be dismissed without proof. <<
- 10-02-2010, 06:24 PM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,405
- Blog Entries
- 7
- Rep Power
- 17
Have you read the API documentation for the Arrays.fill( ... ) method? You should have; it fills an array (the first parameter) with the value mentioned as the second parameter, so it fills the entire array 'used' with the value 'false'. It is quite useless because you have just created the array so it is already filled with values 'false'.
I don't know what that constructor does besides calling its superclass constructor with the same parameter value ...
kind regards,
Jos
Similar Threads
-
Constructor
By arefeh in forum New To JavaReplies: 9Last Post: 01-11-2010, 11:38 AM -
Constructor
By Sarinam in forum AWT / SwingReplies: 1Last Post: 06-19-2008, 08:03 AM -
Calling constructor of parent class from a constructor
By Java Tip in forum Java TipReplies: 0Last Post: 12-19-2007, 09:10 AM -
Calling constructor of same class from a constructor
By Java Tip in forum Java TipReplies: 0Last Post: 12-19-2007, 09:01 AM -
Constructor Help
By bluegreen7hi in forum New To JavaReplies: 2Last Post: 11-15-2007, 05:44 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks