Q. How to Create Map Object ? Create Map Object put some element on it and iterate one by one .

SOLUTION :-

package p2;

import java.util.HashMap;

import java.util.Map;

import java.util.Map.Entry;

public class MapExample {

public static void main(String[] args) {

Map<Integer,String> map =new HashMap<>();

map.put(1, “David”);

map.put(2, “Moksa”);

map.put(3, “Poll”);

map.put(4, “Iliana”);

for(Entry<Integer, String> v1:map.entrySet()) {

System.out.println(v1.getKey()+””+v1.getValue());

}

}

}

 

Leave a Reply

Your email address will not be published. Required fields are marked *

*