数组是不能自动改变大小的,你可以这样: object[] old ... object[] newArray = new object[old.length-1]; for(int i = 0,count=0; i < old.length; i++) { if(old[i].equals(" I hat you")) continue; newArray[count++]=old[i]; } old=newArray;
如果数组很大的话,这样更好: object[] old ... object[] newArray = new object[old.length-1]; int index = 0; for(int i = 0; i < old.length; i++) { if(!old[i].equals(" I hat you")) continue; index = i; break; } System.ArrayCopy(newArray,0,old,0,index); System.ArrayCopy(newArray,index+1,old,index+1,old.length-index); old = newArray;
class A{ String name; int xPos; int yPos; int nWidth; } A[] a = new A(50); 可能是我没有描述清楚,我要做的是对这个数组进行排序,应怎么做?谢谢!
为什么不用Vector,增删都很自由,也不用更改修改的它的大小,它自动为你分配释放的。
object[] old ...
object[] newArray = new object[old.length-1];
for(int i = 0,count=0; i < old.length; i++) {
if(old[i].equals(" I hat you"))
continue;
newArray[count++]=old[i];
}
old=newArray;
object[] old ...
object[] newArray = new object[old.length-1];
int index = 0;
for(int i = 0; i < old.length; i++) {
if(!old[i].equals(" I hat you"))
continue;
index = i;
break;
}
System.ArrayCopy(newArray,0,old,0,index);
System.ArrayCopy(newArray,index+1,old,index+1,old.length-index);
old = newArray;
String name;
int xPos;
int yPos;
int nWidth;
}
A[] a = new A(50);
可能是我没有描述清楚,我要做的是对这个数组进行排序,应怎么做?谢谢!