Created
April 22, 2018 03:14
-
-
Save PandyYang/1f067b9f1553b58945bc8c84286797cf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @author Pandy | |
* @date 2018/4/22 11:08 | |
*/ | |
//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(21)];//即使用new创建数组之后,它还是一个引用数组,知道知道通过创建新的integer元素 | |
System.out.println("length of a = "+ a.length); | |
for (int i = 0;i<a.length;i++) | |
a[i] = rand.nextInt(500);//如果没有创建对象,并且试图使用数组中的空引用,会在运行时产生一个异常 | |
System.out.println(Arrays.toString(a)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment