删除list中指定值的元素
public class ListRemoveAll {
public static void main(String[] args) {
// TODO Auto-generated method stub
List<Long> list1 = new ArrayList<Long>();
List<Long> list2 = new ArrayList<Long>();
for(int i =0;i<10;i++){
list1.add(Long.parseLong(i+""));
list2.add(Long.parseLong(i+""));
}
for(int i =10;i<20;i++){
list1.add(Long.parseLong(i+""));
}
list1.add(55L);
System.out.println(list1.toString());
System.out.println(list2.toString());
list1.remove(55L);
System.out.println(list1.toString());
}
}
其结果为
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 55]
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]
原来list.remove();不只是可以删除所引元素,也可以删除object