Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
package Collection;
import java.util.*;
public class HashSetDemo2 {
public static void main(String args[]){
Set<String> set1 = new HashSet<>();
set1.add("London");
set1.add("Paris");
set1.add("New York");
set1.add("San Francisco");
set1.add("Beijing");
System.out.println("set1 = " + set1);
System.out.println("set1 size = " + set1.size());
set1.remove("London");
System.out.println("set1 = " + set1);
System.out.println("set1 size = " + set1.size());
Set<String> set2 = new HashSet<>();
set2.add("London");
set2.add("Shanghai");
set2.add("Paris");
System.out.println("set2 = " + set2);
System.out.println("set2 size = " +set2.size());
System.out.println("Ankara set2'de mi -> " + set2.contains("Eskişehir"));
set1.addAll(set2);
System.out.println("Set1'e set2 eklendikten sonra = " + set1);
set1.retainAll(set2);
System.out.println("Ortak elemanlar = " + set1);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment