java 刪除整數元素集合中的元素

1. 簡介spa

對於整數類型的元素集合,例如{1, 2, 3, 4, 5},進行元素刪除時須要注意。在List中刪除操做有remove(int index)和remove(Object o),code

查看兩種方式的注意事項。blog

2. 示例索引

(1)刪除指定索引的元素;rem

(2)刪除指定的元素;class

1         Integer[] array2 = new Integer[]{1,2,3,4};
2         List<Integer> list2 = new ArrayList<>(Arrays.asList(array2));  
3         list2.remove(1);      // (1) 4         System.out.println(list2);       // [1, 3, 4]
5         list2.remove(Integer.valueOf(1));     // (2) 6         System.out.println(list2);     //    [3, 4]

!!!List

相關文章
相關標籤/搜索