如何在Java中从数组中删除元素
下面的示例演示如何从数组中删除元素。
示例
import java.util.ArrayList; public class Main {public static void main(String[] args) {
ArrayList objArray = new ArrayList();
objArray.clear();
objArray.add(0,"0th element");
objArray.add(1,"1st element");
objArray.add(2,"2nd element");
System.out.println("Array before removing an element"+objArray);
objArray.remove(1);
objArray.remove("0th element");
System.out.println("Array after removing an element"+objArray);
}
}
输出结果
上面的代码示例将产生以下结果。
Array before removing an element[0th element, 1st element, 2nd element]Array after removing an element[2nd element]
以上是 如何在Java中从数组中删除元素 的全部内容, 来源链接: utcz.com/z/345407.html