java list 去重问题
java list去重问题 子元素为list
import java.util.*; public class ListRemoveDuplicate { public static void main(final String[] args) { List<Object> testList = new ArrayList<>(); List<Object> elementList1 = new ArrayList<>(); elementList1.add("1"); elementList1.add("2"); elementList1.add("3"); List<Object> elementList2 = new ArrayList<>(); elementList2.add("4"); elementList2.add("5"); elementList2.add("6"); List<Object> elementList3 = new ArrayList<>(); elementList3.add("1"); elementList3.add("2"); elementList3.add("3"); testList.add(elementList1); testList.add(elementList2); testList.add(elementList3); System.out.println("before:" + testList); System.out.println("after:" + removeDuplicate(testList)); } public static List removeDuplicate(final List inputList) { HashSet<Object> hashSet = new HashSet<>(inputList); List<Object> outputList = new ArrayList<>(); outputList.addAll(hashSet); return outputList; } }
before:[[1, 2, 3], [4, 5, 6], [1, 2, 3]] after:[[1, 2, 3], [4, 5, 6]]