+++++++++++++ HashMap +++++++++++
- HashMap contains values based on the key. It implements the Map interface and extends the AbstractMap class.
- It contains only Uniq elements
- It may have one null key and multiple null values.
- It maintains no order.
Sample code for HashMap:
package collections;
import java.util.*;
import java.util.HashMap;
import java.util.Map;
public class HashMapTest {
public static void main(String[] args) {
HashMap<Integer,String> hm=new HashMap<Integer,String>();
hm.put(100,"pabbu");
hm.put(200, "reddy");
hm.put(200, "reddy");
for(HashMap.Entry m:hm.entrySet())
{
System.out.println(m.getKey() + " "+m.getValue());
}
}
}
Output:
100 pabbu
200 reddy
- HashMap contains values based on the key. It implements the Map interface and extends the AbstractMap class.
- It contains only Uniq elements
- It may have one null key and multiple null values.
- It maintains no order.
Sample code for HashMap:
package collections;
import java.util.*;
import java.util.HashMap;
import java.util.Map;
public class HashMapTest {
public static void main(String[] args) {
HashMap<Integer,String> hm=new HashMap<Integer,String>();
hm.put(100,"pabbu");
hm.put(200, "reddy");
hm.put(200, "reddy");
for(HashMap.Entry m:hm.entrySet())
{
System.out.println(m.getKey() + " "+m.getValue());
}
}
}
Output:
100 pabbu
200 reddy
No comments:
Post a Comment