LinkedHashMap( )The second form initializes the LinkedHashMap with the elements from m:
LinkedHashMap(Map m)The third form initializes the capacity:
LinkedHashMap(int capacity)The fourth form initializes both capacity and fill ratio. The meaning of capacity and fill ratio are the same as for HashMap:
LinkedHashMap(int capacity, float fillRatio)The last form allows you to specify whether the elements will be stored in the linked list by insertion order, or by order of last access. If Order is true, then access order is used. If Order is false, then insertion order is used.
LinkedHashMap(int capacity, float fillRatio, boolean Order)
SN | Methods with Description |
---|---|
1 | void clear() Removes all mappings from this map. |
2 | boolean containsKey(Object key) Returns true if this map maps one or more keys to the specified value. |
3 | Object get(Object key) Returns the value to which this map maps the specified key. |
4 | protected boolean removeEldestEntry(Map.Entry eldest) Returns true if this map should remove its eldest entry. |
import java.util.*; class Simple{ public static void main(String args[]){ LinkedHashMap hm=new LinkedHashMap(); hm.put(100,"Dinesh"); hm.put(101,"Sweety"); hm.put(102,"Nimmo"); Set set=hm.entrySet(); Iterator itr=set.iterator(); while(itr.hasNext()){ Map.Entry m=(Map.Entry)itr.next(); System.out.println(m.getKey()+" "+m.getValue()); } } }
Labels: collection