Hallo,
ne kurze frage, ich komm ned dahinter.
ich hab ne arraylist und möchte diese per system.arraycopy in ein array reinkopieren und ausgeben. davor wird die arraylist noch sortiert.
hier mein ansatz
|
C-/C++-Quelltext
|
1
2
3
4
5
6
7
8
9
10
11
|
´
List<Integer> ArrayTest = new ArrayList<Integer>();
// ....
for(int i=0; i<10; i++)
ArrayTest.add((int)(Math.random()*10));
Collections.sort(ArrayTest);
int TempArray[] = new int[10];
System.arraycopy(ArrayTest.toArray(), 0, TempArray, 0, 10);
System.out.println("\n\n"+ArrayTest+"\n\n"+TempArray);
|
Exception in thread "main" java.lang.ArrayStoreException
at java.lang.System.arraycopy(Native Method)
at Aufgabe2.main(Aufgabe2.java:66)
das is der error. verstehs ned ganz, warums ned geht
mfg
Drac
edit:
|
C-/C++-Quelltext
|
1
2
3
4
5
6
|
for(int i=0; i<10; i++)
ArrayTest.add((int)(Math.random()*10));
Collections.sort(ArrayTest);
Integer TempArray[] = new Integer[10];
System.arraycopy(ArrayTest.toArray(), 0, TempArray, 0, 10);
System.out.println("\n\n"+ArrayTest+"\n\n"+TempArray);
|
wenn ichs so umschreibe führt er es mal aus, aber die ausgabe des TempArrays ist merkwürdig
|
C-/C++-Quelltext
|
1
2
3
|
[0, 0, 1, 2, 3, 3, 4, 5, 5, 9]
[Ljava.lang.Integer;@7c6768
|