Map in collection
------------------
Map will not maintain insertion order.
Map will store data based on key value pair
Map will store only unique keys.
Hash Map
--------
A Hash Map contains values based on the key.
It contains only unique keys.
It maintains no order.
Example:
--------
package Test;
import [Link];
import [Link];
public class ExampleHashSet
{
public static void main(String[] args)
{
Map<Integer,Integer> map = new HashMap<Integer,Integer>();
[Link](1, 100);
[Link](20, 100);
[Link](30, 100);
[Link](4, 100);
[Link](map);
}
}
//output: {1=100, 4=100, 20=100, 30=100}
To get Data from Hash Map we have use method �get�
--------------------------------------------------
package Test;
import [Link];
import [Link];
public class ExampleHashSet
{
public static void main(String[] args)
{
Map<Integer,Integer> map = new HashMap<Integer,Integer>();
[Link](1, 100);
[Link](20, 100);
[Link](30, 400);
[Link](30, 100);
[Link](30, 600);
[Link](30, 100);
[Link](null, 100);
[Link]([Link](1));
[Link]([Link](20));
[Link]([Link](30));
}
}
//output:
100
100
100
Linked Hash Map will maintain insertion order
---------------------------------------------
Example:
--------
package Test;
import [Link];
import [Link];
public class ExampleHashSet
{
public static void main(String[] args)
{
Map<Integer,Integer> map = new
LinkedHashMap<Integer,Integer>();
[Link](1, 100);
[Link](20, 100);
[Link](30, 100);
[Link](4, 100);
[Link](map);
}
}
//output: {1=100, 20=100, 30=100, 4=100}
Tree Map will store the data in ascending order
-----------------------------------------------
package Test;
import [Link];
import [Link];
public class ExampleHashSet
{
public static void main(String[] args)
{
Map<Integer,Integer> map = new TreeMap<Integer,Integer>();
[Link](1, 100);
[Link](20, 100);
[Link](30, 100);
[Link](4, 100);
[Link](map);
}
}
//output: {1=100, 4=100, 20=100, 30=100}