Answers for "iterate over hash java"

31

java iterate through hashmap

for (Map.Entry<String, String> entry : yourHashMap.entrySet()) {
	System.out.println(entry.getKey() + " = " + entry.getValue());
}
Posted by: Guest on April-13-2020
1

HashSet iterator() method in java

import java.util.HashSet;
import java.util.Iterator;
public class HashSetIteratorMethodExample
{
   public static void main(String[] args)
   {
      HashSet<String> hs = new HashSet<String>();
      hs.add("Welcome");
      hs.add("hello");
      hs.add("world");
      hs.add("core");
      hs.add("java");
      System.out.println("HashSet values are: " + hs);
      // create an Iterator
      Iterator<String> value = hs.iterator();
      System.out.println("iterator values are: ");
      while(value.hasNext())
      {
         System.out.println(value.next());
      }
   }
}
Posted by: Guest on October-28-2020

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language