Skip to content

Instantly share code, notes, and snippets.

@uncoded-ro
Created January 12, 2020 06:50
Show Gist options
  • Save uncoded-ro/b28c71acf6124f3ef1c8e00dc3deded1 to your computer and use it in GitHub Desktop.
Save uncoded-ro/b28c71acf6124f3ef1c8e00dc3deded1 to your computer and use it in GitHub Desktop.
package ro.virtualcampus.set;
import java.util.HashSet;
public class AppHashSet {
public static void main(String[] args) {
HashSet<String> multime1 = new HashSet<String>();
multime1.add("Iulian");
multime1.add("Corina");
multime1.add("Ghita");
multime1.add("Silviu");
System.out.printf("multime nume %s %n", multime1);
for (String element : multime1) {
System.out.printf("%s, ", element);
}
System.out.printf("%n");
HashSet<String> multime2 = new HashSet<String>();
multime2.add("Maria");
multime2.add("Ghita");
multime2.add("Irina");
multime1.addAll(multime2);
System.out.printf("multime nume %s %n", multime1);
multime1.removeAll(multime2);
System.out.printf("multime nume %s %n", multime1);
multime1.retainAll(multime2);
System.out.printf("multime nume %s %n", multime1);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment