I've got a problem, probably an easy one, but i can't manage to solve it
:-(
I try to fill an ArrayList and then print it, but since Java pass only
handles to object, he just keep the last value for every item in the
ArrayList. I've read something about clone, but i can't make it work.
The source is:
import java.util.ArrayList;
import java.lang.Double;
import java.util.Random;
import java.lang.System;
public class myclass {
public ArrayList al;
public Double d;
public Random alea;
public myclass() {
al = new ArrayList(10);
alea = new Random();
}
public static void main (String[] args) {
myclass c = new myclass();
double real;
int i;
// Fill the ArrayList
for (i = 0; i<10; i++) {
c.d = new Double(c.alea.nextDouble());
c.al.add(i,c.d);
System.out.println("Start: " + ((Double) c.al.get(i)).toString());
}
// Print the data from the ArrayList
for (i = 0; i<10; i++) {
c.al.add(i,c.d);
System.out.println("End: " + ((Double) c.al.get(i)).toString());
}
}
}
And the results are (those are an example, because i use a Random
generator):
Start: 0.28012035030857985
Start: 0.40180116776466135
Start: 0.6795764373219171
Start: 0.08519019735402789
Start: 0.18054903350688734
Start: 0.14224057950044477
Start: 0.23224765920471468
Start: 0.623506361467136
Start: 0.2183654727784211
Start: 0.3157707740311705
End: 0.3157707740311705
End: 0.3157707740311705
End: 0.3157707740311705
End: 0.3157707740311705
End: 0.3157707740311705
End: 0.3157707740311705
End: 0.3157707740311705
End: 0.3157707740311705
End: 0.3157707740311705
End: 0.3157707740311705
Thanks in advance.
----------------------------------------------------------------------
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]