Collection Interface. it has got two kind of implementations. List Set If you want a dictionary structure, Map is good to you. But all of them are special for object only, if you have got primitive (int, byte), you have got to transfer it.
int[] a = new int[1]; for ( int i = 0; i < 100; i++ ) { if ( i >= a.length ) { int[] b = new int[i+1]; System.arraycopy(a,0,b,0,a.length); a = b; } a[i] = i; } 不过,每次加1,性能不好,尤其是对于比较大的数组 最好还是采用Vector的增长策略,每次加倍 int[] b = new int[i*2];
使用vector对象阿这个东西正好适合你的这种情况阿
具体用法见《thinking in java》/*--by bookbobby(书呆)-+
| |
| 你说爱我只是习惯 |
| 再也不是喜欢 |
| 我给你的爱 |
| 已不再温暖 |
| |
+--by bookbobby(书呆)-*/
it has got two kind of implementations.
List
Set
If you want a dictionary structure, Map is good to you.
But all of them are special for object only, if you have got primitive (int, byte), you have got to transfer it.
for ( int i = 0; i < 100; i++ ) {
if ( i >= a.length ) {
int[] b = new int[i+1];
System.arraycopy(a,0,b,0,a.length);
a = b;
}
a[i] = i;
}
不过,每次加1,性能不好,尤其是对于比较大的数组
最好还是采用Vector的增长策略,每次加倍 int[] b = new int[i*2];