?? containercomparison.java
字號:
package chapter16;
import java.util.*;
class BerylliumSphere{
private static long counter;
private final long id=counter++;
public String toString(){
return "Sphere "+id;
}
}
public class ContainerComparison {
public static void main(String args[]){
BerylliumSphere[] spheres=new BerylliumSphere[10];
/*
* 上面的語句說明Java可以現時實例化多個對象
*/
for(int i=0;i<5;i++){
spheres[i]=new BerylliumSphere();
/*
* 每實例化開一次,c
*
* ounter++運行一次
*/
}
System.out.println(Arrays.toString(spheres));
/*
* Arrays.toString()是java的一個方法,不過,可以自己寫toString方法,這樣,
* 本程序的結果不是
* [chapter16.BerylliumSphere@1fb8ee3, chapter16.BerylliumSphere@61de33, chapter16.BerylliumSphere@14318bb, chapter16.BerylliumSphere@ca0b6, chapter16.BerylliumSphere@10b30a7, null, null, null, null, null]
chapter16.BerylliumSphere@10b30a7
而是
[Sphere 0, Sphere 1, Sphere 2, Sphere 3, Sphere 4, null, null, null, null, null]
Sphere 4
*/
System.out.println(spheres[4]);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -