2
3 class BerylliumSphere
4 {
5 private static long counter;
6 private final long id = counter++;
7 public String toString()
8 {
9 return "Sphere " + id;
10 }
11 }
12
13 public class ContainerComparison {
14 public static void main(String[] args)
15 {
16 BerylliumSphere[] spheres = new BerylliumSphere[10];
17 for(int i=0; i<5; i++)
18 {
19 spheres[i] = new BerylliumSphere();
20 }
21 System.out.println(Arrays.toString(spheres));
22 System.out.println(spheres[4]);
23
24 List<BerylliumSphere> sphereList = new ArrayList<BerylliumSphere>();
25 for(int i=0; i<5; i++)
26 {
27 sphereList.add(new BerylliumSphere());
28 }
29 System.out.println(sphereList);
30 System.out.println(sphereList.get(4));
31
32 int[] integers = {0,1,2,3,4,5};
33 System.out.println(Arrays.toString(integers));
34 System.out.println(integers[4]);
35
36 List<Integer> intList = new ArrayList<Integer>(Arrays.asList(0,1,2,3,4,5));
37 intList.add(97);
38 System.out.println(intList);
39 System.out.println(intList.get(4));
40 }
41 }