23 lines
741 B
Java
23 lines
741 B
Java
// housekeeping/ArrayClassObj.java
|
|
// (c)2016 MindView LLC: see Copyright.txt
|
|
// We make no guarantees that this code is fit for any purpose.
|
|
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
|
|
// Creating an array of nonprimitive objects.
|
|
import java.util.*;
|
|
|
|
public class ArrayClassObj {
|
|
public static void main(String[] args) {
|
|
Random rand = new Random(47);
|
|
Integer[] a = new Integer[rand.nextInt(20)];
|
|
System.out.println("length of a = " + a.length);
|
|
for(int i = 0; i < a.length; i++)
|
|
a[i] = rand.nextInt(500); // Autoboxing
|
|
System.out.println(Arrays.toString(a));
|
|
}
|
|
}
|
|
/* Output:
|
|
length of a = 18
|
|
[55, 193, 361, 461, 429, 368, 200, 22, 207, 288, 128, 51,
|
|
89, 309, 278, 498, 361, 20]
|
|
*/
|