A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.tutorialspoint.com/java/util/java_util_linkedhashmap.htm below:

Java LinkedHashMap Class

Java LinkedHashMap Class Introduction

The Java LinkedHashMap class is Hash table and Linked list implementation of the Map interface, with predictable iteration order. Following are the important points about LinkedHashMap −

Class declaration

Following is the declaration for java.util.LinkedHashMap class −

public class LinkedHashMap<K,V>
   extends HashMap<K,V>
   implements Map<K,V>
Parameters

Following is the parameter for java.util.LinkedHashMap class −

Class constructors Sr.No. Constructor & Description 1

LinkedHashMap()

This constructs an empty insertion-ordered LinkedHashMap instance with the default initial capacity (16) and load factor (0.75).

2

LinkedHashMap(int initialCapacity)

This constructs an empty insertion-ordered LinkedHashMap instance with the specified initial capacity and a default load factor (0.75).

3

LinkedHashMap(int initialCapacity, float loadFactor)

This constructs an empty insertion-ordered LinkedHashMap instance with the specified initial capacity and load factor.

4

LinkedHashMap(int initialCapacity, float loadFactor, boolean accessOrder)

This constructs an empty LinkedHashMap instance with the specified initial capacity, load factor and ordering mode.

5

LinkedHashMap(Map<? extends K,? extends V> m)

This constructs an insertion-ordered LinkedHashMap instance with the same mappings as the specified map.

Class methods Methods inherited

This class inherits methods from the following classes −

Getting a Value from LinkedHashMap Example

The following example shows the usage of Java LinkedHashMap get() method to get a value based on a key from a Map. We've created a Map object of Integer,Integer. Then few entries are added, map is printed. Using get() method, a value is retrieved and printed.

package com.tutorialspoint;

import java.util.LinkedHashMap;

public class LinkedHashMapDemo {
   public static void main(String args[]) {
      
      // create hash map
      LinkedHashMap<Integer,Integer> newmap = new LinkedHashMap<>();

      // populate hash map
      newmap.put(1, 1);
      newmap.put(2, 2);
      newmap.put(3, 3); 

      System.out.println("Initial map elements: " + newmap);

      System.out.println("Value: " + newmap.get(1));
   }    
}
Output

Let us compile and run the above program, this will produce the following result.

Initial map elements: {1=1, 2=2, 3=3}
Value: 1

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4