Remove duplicates from List using Guava

后端 未结 6 1093
清歌不尽
清歌不尽 2020-12-08 06:45

How can we remove duplicates from List with the help of Guava api?

Currently I am following this:

private List removeDuplic         


        
6条回答
  •  忘掉有多难
    2020-12-08 07:36

    with generic predicate

    class DuplicateRemover implements Predicate {
    
        private final Set set = new HashSet<>();
    
        @Override
        public boolean apply(T input) {
    
            boolean flag = set.contains(input);
    
            if (!flag) {
                set.add(input);
            }
    
            return !flag;
        }
    
    }
    

提交回复
热议问题