Map<String, String> map = new HashMap<>();
        map.put("110"."Nature"); map.put("120"."Hospital"); map.put("119"."Fire");

        System.out.println("Method 1: map.keyset () traversal");
        for(String key : map.keySet()){
            System.out.println(key+":"+map.get(key));
        }

        System.out.println("Method 2: Iterator through map. entrySet");
        Iterator<Map.Entry<String, String>> iterator = map.entrySet().iterator();
        while(iterator.hasNext()){
            Map.Entry<String, String> next = iterator.next();
            System.out.println(next.getKey()+":"+next.getValue());
        }

        System.out.println("Method 3: Traverse through Map.entrySet");
        for(Map.Entry<String, String> entry : map.entrySet()){
            System.out.println(entry.getKey()+":"+entry.getValue());
       
Copy the code