当前位置:网站首页>Guava common collection tool classes

Guava common collection tool classes

2022-06-25 05:38:00 Which floor do you rate moto

  • Sets Tool class operations Set aggregate
    • Combine , Delivery and , Difference set , Decompose all subsets in the set , Find the Cartesian product of two sets
public class sets {
    public static void main(String[] args) {
        Set<Integer> set1 = Sets.newHashSet(1,2,3,4);
        Set<Integer> set2 = Sets.newHashSet(4,5,6);
        // Combine 
        Set<Integer> integerSet = Sets.union(set1,set2);
        System.out.println(integerSet);
​
        // intersection 
        Set<Integer> intersectionSet = Sets.intersection(set1,set2);
        System.out.println(intersectionSet);
​
        // Difference set : The element belongs to set1 It doesn't belong to set2
        Set<Integer> differenceSet = Sets.difference(set1,set2);
        System.out.println(differenceSet);
        // Relative difference set : Belong to A It doesn't belong to B, Belong to B It doesn't belong to A
        Set<Integer> symmetricDifference = Sets.symmetricDifference(set1,set2);
        System.out.println(symmetricDifference);
​
        // Decompose all subsets in the set 
        Set<Set<Integer>> powerSet = Sets.powerSet(set1);
        System.out.println(JSON.toJSON(powerSet));
​
        // Cartesian product of two sets 
        Set<List<Integer>> cartesianProduct = Sets.cartesianProduct(set1,set2);
        System.out.println(JSON.toJSON(cartesianProduct));
    }
  • Lists Tool class operations List aggregate
    • reverse , Split
public class lists {
    public static void main(String[] args) {
        List<Integer> list = Lists.newArrayList(1,2,3,4,5,6,7);
        //3 individual 3 Split up : Support with 3 An interface for querying a group of order numbers 
        List<List<Integer>>lists = Lists.partition(list,3);
        System.out.println(lists);
        // reverse 
        List<Integer> integerList = Lists.reverse(list);
        System.out.println(integerList);

    }
}

原网站

版权声明
本文为[Which floor do you rate moto]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202210504099665.html