方法一: /** List order not maintained **/ public static void removeDuplicate(ArrayList arlList) { HashSet h = new HashSet(arlList); arlList.clear(); arlList.addAll(h); } 方法二: /** List order maintained **/ public static void removeDuplicateWithOrder(Arra…
今天一朋友问了个问题,对于如下一段代码,运行后会有怎样的结果? public class ArrayListTest { public static void main(String[] args) { List<Integer> list = new ArrayList<>(Arrays.asList(1, 2, 3, 4, 5)); for (Integer num : list) { if(num == 4){ list.remove(num); } } System.out…