Guava 학습

1403 단어

guava Splitter 학습

  @Test
  public void Str2ListGuava(){
        String str = "1,2,3,4,5,6,7,8,30,,";
        //  
        List list1 = Splitter.on(',').splitToList(str);
        // 
        List list2 = Splitter.on(',').omitEmptyStrings().splitToList(str).stream().map(Integer::parseInt).collect(Collectors.toList());
        System.out.println(" :" + list1);
        System.out.println(" :" + list2);
    }


guava Sets 컬렉션 클래스 교차 컬렉션, 차 컬렉션, 병합

 public static void main(String[] args) {
        List list1 = Lists.newArrayList(1, 2, 3, 4, 5, 6);
        List list2 = Lists.newArrayList(3, 4, 5, 6, 7, 8, 9);

        //  
        System.out.println(" :");
        Sets.SetView intersection = Sets.intersection(Sets.newHashSet(list1), Sets.newHashSet(list2));

        //  
        System.out.println(" :");
        Sets.SetView diff = Sets.difference(Sets.newHashSet(list1), Sets.newHashSet(list2));
 
        //  
        System.out.println(" :");
        Sets.SetView union = Sets.union(Sets.newHashSet(list1), Sets.newHashSet(list2));
        //  List
        List integers = Lists.newArrayList(union);
    }

좋은 웹페이지 즐겨찾기