package TestOne;
import java.util.Arrays;
public class TestOperateArray2 {
public static void main(String[] args) {
int[] array = new int[]{2, 3, 4, 5, 9, 6, 7};
//Delete the third element 4
int[] newArray = new int[array.length - 1];
int flag = 3;
for (int i = 0; i < newArray.length; i++) {
if (i < flag - 1) {
newArray[i] = array[i];
} else {
newArray[i] = array[i + 1];
}
}
System.out.println(Arrays.toString(newArray));
}
}
数组元素的删除
最新推荐文章于 2024-01-11 11:42:42 发布