ArrayNew:初始化int数组和Integer数组
class ArrayNew {
public static void chapter5_8() {
int[] a = new int[10];
Integer[] b = new Integer[10];
Random random = new Random(7);
for(int i=0;i<10;i++) {
a[i] = random.nextInt(10);
b[i] = random.nextInt(20);
}
System.out.println("a.length:" + a.length);
System.out.println(Arrays.toString(a));
System.out.println("b.length:" + b.length);
System.out.println(Arrays.toString(b));
}
};
输出:
a.length:10
[6, 5, 0, 8, 0, 0, 8, 5, 1, 7]
b.length:10
[4, 4, 14, 9, 14, 12, 11, 2, 18, 19]
NewVarArgs:可变参数列表
class NewVarArgs {
static class A {}
static void printObject(Object... args) {
for(Object object:args) {
System.out.println("object:" + object);
}
}
public static void chapter5_8() {
printObject(new Integer(7),3.14F,new A());
}
};
输出:
object:7
object:3.14
object:thinkinjava.hyh.NewVarArgs$A@7a5d012c