Guest User

Guava Set Unions

a guest
Jan 4th, 2019
276
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.42 KB | None | 0 0
  1. import com.google.common.collect.*;
  2. import java.util.*;
  3.  
  4. class Example {
  5.     public static void main(String[] args) {
  6.         Set<String> a = Collections.newSetFromMap(new IdentityHashMap<>());
  7.         Set<String> b = new HashSet<>();
  8.        
  9.         a.add("X");
  10.         b.add(new String("X"));
  11.        
  12.         System.out.println(Sets.union(a, b)); // [X, X]
  13.         System.out.println(Sets.union(b, a)); // [X]
  14.     }
  15. }
Advertisement
Add Comment
Please, Sign In to add comment