Created
June 6, 2017 19:36
-
-
Save MericBERBER/30c2c9bcd7940ec8127f186c1655f99b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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