Java Map Example (Add , List - Generic)

package com.practice.map;

import java.util.*;

class MapInterfaceExample {
public static void main(String args[]) {
Map<Integer, String> map = new HashMap<>();

map.put(1, "m");
map.put(2, "a");
map.put(3, "d");
map.put(4, "d");
map.put(5, "y");

for(Map.Entry<Integer, String> mm:map.entrySet())
{
System.out.println(mm.getValue()+" "+mm.getKey()+"");
}

}
}

Output :

m 1
a 2
d 3
d 4
y 5

Comments

Popular Posts