Home > Java > javaTutorial > body text

Java simple method to traverse HashMap

高洛峰
Release: 2017-01-19 10:06:47
Original
1226 people have browsed it

The example of this article describes the simple method of traversing HashMap in java. Share it with everyone 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); 
     }
  }
}
Copy after login

I hope this article will be helpful to everyone’s java programming.

For more articles related to the simple method of traversing HashMap in Java, please pay attention to the PHP Chinese website!


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!