3月 012018
 

单个List数据去重

思路:利用HashSet
代码:

        List<String> list = new ArrayList<>();
        list.add("a");
        list.add("b");
        list.add("c");
        list.add("c");
        list.add("c");
        for (String string : list) {
            System.out.println(string);
        }
        System.out.println("=============================");
        //转成set
        List<String> listWithoutDup = new ArrayList<>(new HashSet<>(list));
        for (String str : listWithoutDup) {
            System.out.println(str);
        }

Continue reading »