Creating a LinkedHashMap
Basic Declaration
Like HashMap, declare variables using the parent Map interface:
import java.util.LinkedHashMap;
import java.util.Map;
// Map<KeyType, ValueType> map = new LinkedHashMap<>();
Map<String, String> contacts = new LinkedHashMap<>();
Ensure you use Wrapper types instead of primitives for keys and values.
LinkedHashMap Constructors
- Default Constructor: Sets initial capacity to 16, load factor to 0.75, and insertion-order mode.
- Initial Capacity Constructor:
- Access-Order Constructor: If the third argument is set to
true, the map uses access-order instead of insertion-order:
Back to LinkedHashMap Home: LinkedHashMap Index