|
| 1 | +package btp.oneP; |
| 2 | + |
| 3 | +import java.util.Arrays; |
| 4 | + |
| 5 | +public class ArrayOptions { |
| 6 | + |
| 7 | + public static void main(String[] args) { |
| 8 | + BerylliumSphere[] a = null; |
| 9 | + BerylliumSphere[] b = new BerylliumSphere[5]; |
| 10 | + System.out.println(a); |
| 11 | + System.out.println(b); |
| 12 | + System.out.println(Arrays.toString(b)); |
| 13 | + |
| 14 | + BerylliumSphere[] c = new BerylliumSphere[4]; |
| 15 | + for(int i=0;i<c.length;i++){ |
| 16 | + if(null == c[i]){ |
| 17 | + c[i] = new BerylliumSphere(); |
| 18 | + } |
| 19 | + } |
| 20 | + |
| 21 | + BerylliumSphere[] d = { |
| 22 | + new BerylliumSphere(),new BerylliumSphere(),new BerylliumSphere() |
| 23 | + }; |
| 24 | + a = new BerylliumSphere[]{ |
| 25 | + new BerylliumSphere(),new BerylliumSphere(),new BerylliumSphere() |
| 26 | + }; |
| 27 | + System.out.println("a.length:"+a.length); |
| 28 | + System.out.println("b.length:"+b.length); |
| 29 | + System.out.println("c.length:"+c.length); |
| 30 | + System.out.println("d.length:"+d.length); |
| 31 | + |
| 32 | + a = d; |
| 33 | + System.out.println("a.length:"+a.length); |
| 34 | + |
| 35 | + int[] e; |
| 36 | + int[] f = new int[4]; |
| 37 | + System.out.println("f:"+Arrays.toString(f)); |
| 38 | + int[] g = new int[4]; |
| 39 | + for(int i=0;i<g.length;i++){ |
| 40 | + g[i] = i*i; |
| 41 | + } |
| 42 | + int[] h = {11,47,93}; |
| 43 | + System.out.println("f.length:"+f.length); |
| 44 | + System.out.println("g.length:"+g.length); |
| 45 | + System.out.println("h.length:"+h.length); |
| 46 | + |
| 47 | + e = h; |
| 48 | + System.out.println("e.length:"+e.length); |
| 49 | + e = new int[]{1,2}; |
| 50 | + System.out.println("e.length:"+e.length); |
| 51 | + |
| 52 | + char[] cs = new char[5]; |
| 53 | + System.out.println(Arrays.toString(cs)); |
| 54 | + } |
| 55 | + |
| 56 | +} |
0 commit comments