×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Added: May 5, 2021 3:46 PM
Modified: May 5, 2021 3:47 PM
Views: 3994
Tags: collections
  1.  
  2.     public static void main(String[] args) {
  3.  
  4.         //Initialisieren wie ArrayLists
  5.         var colors = new HashSet<String>();
  6.  
  7.         // use add() method to add values in the hash set
  8.         colors.add("Red");
  9.         colors.add("Green");
  10.         colors.add("Black");
  11.         colors.add("White");
  12.         colors.add("Pink");
  13.         colors.add("Yellow");
  14.  
  15.         //set Iterator
  16.         Iterator<String> p = colors.iterator();
  17.  
  18.         //Iterate the HashSet
  19.         while(p.hasNext()){
  20.             System.out.println(p.next());
  21.         }
  22.     }
  23. }
  24.