This article example tells the simple method of java traversing HashMap. Share it for your reference. The specific implementation method is as follows:
import java.util.HashMap; import java.util.Iterator; import java.util.Set; public class HashSetTest { public static void main(String[] args) { HashMap map = new HashMap(); map.put("a ", "aa"); map.put("b", "bb"); map.put("c", "cc"); map.put("d", "dd"); map.put( "e", "ee"); Set set = map.keySet(); for(Iterator itr=set.iterator();itr.hasNext();){ String value =(String) itr.next(); String key = (String)map.get(value); System.out.println(value+"="+key); } } }I hope this article will be helpful to everyone's Java programming.