Map<Integer,String> map=new HashMap<>(); map.put(1,"john"); map.put(2,"kale"); for(Map.Entry<Integer,String> x:map.entrySet()){ System.out.println(x.getKey()); System.out.println(x.getValue()); }