https://guava-libraries.googlecode.com/svn/tags/release04/javadoc/com/google/common/collect/Sets.html


Set instace 생성/변환할 때 사용한다. 


Sets.newCopyOnWriteArraySet()

Sets.newConcurrentHashSet()

Sets.newLinkedHashSet()

Sets.newTreeSet()

Sets.newHashSet()

Sets.newHashSetWithExpectedSize(members.size())

Sets.immutableEnumSet(encodeKey)  



가장 많이 유용한 것은 Set간의 intersection, union이다. 


@Test
public void test() {

Set<String>
set1 = new HashSet<String>();
set1.add("a");
set1.add("b");
set1.add("c");

Set<String>
set2 = new HashSet<String>();
set2.add("c");
set2.add("d");
set2.add("e");

Set<String>
intersection = Sets.intersection(set1, set2);
System.
out.println(Arrays.toString(intersection.toArray()));

Set<String>
union = Sets.union(set1, set2);
System.
out.println(Arrays.toString(union.toArray()));
}



결과

[c]

[b, c, a, d, e]

Posted by '김용환'
,