-
- import java.util.HashMap;
- import java.util.Map;
-
- public class Mapdemo{
- public static void main(String[] args){
- Map<String,Integer> map = new HashMap<String,Integer>();
- map.put("first", 1);
- map.put("second", 2);
- map.put("third", 3);
-
- for(Object o:map.values()){
- int value = (Integer)o;
- System.out.println(value);
- }
-
- for(Object o:map.keySet()){
- String key = o.toString();
- int value = (Integer) map.get(o);
- System.out.println(key+"_"+value);
- }
-
- for(Map.Entry<String, Integer> entry:map.entrySet()){
- String key = entry.getKey();
- int value = entry.getValue();
- System.out.println(key+":"+value);
- }
- }
- }