Modifier and Type | Class and Description |
---|---|
static class |
Maps.Builder<K,V>
Wraps around
map to allow its fluent creation and modification. |
Modifier and Type | Method and Description |
---|---|
static <K,V> Maps.Builder<K,V> |
builder()
|
static <K,V> Maps.Builder<K,V> |
builder(Map<K,V> map)
Wraps a builder around
map to allow its fluent creation and
modification. |
static <K,V> Map.Entry<K,V> |
entry(K key,
V value)
Creates an
Map.Entry representing a mapping from the specified key to the
specified value. |
static <K,V> Map<K,V> |
sort(Map<K,V> unsorted,
Comparator<Map.Entry<K,V>> comparator)
|
public static <K,V> Maps.Builder<K,V> builder()
HashMap
to allow fluent creation and
modification of a Map
.
To use strict typing Java compilers might need some hint about your maps key and value types in front of this method call. Check out the below example.
Usage example: The following shows how to create an unmodifiable map containing three entries.
Map<String, Integer> map = Maps.<String, Integer>builder() .put("France", 33) .put("Germany", 49) .put("Italy", 39) .unmodifiable();
K
- type of the maps keyV
- type of the maps valuepublic static <K,V> Maps.Builder<K,V> builder(Map<K,V> map)
map
to allow its fluent creation and
modification.
Usage example 1: The following shows how to create an unmodifiable
LinkedHashMap
containing three entries.
Map<String, Integer> map = Maps.builder(new LinkedHashMap<String, Integer>()) .put("France", 33) .put("Germany", 49) .put("Italy", 39) .unmodifiable();
Usage example 2: The following shows how to create a
NavigableMap
based on a TreeMap
.
NavigableMap<String, Integer> map = Maps.builder(new TreeMap<String, Integer>()) .put("France", 33) .put("Germany", 49) .put("Italy", 39) .get();
K
- type of the maps keyV
- type of the maps valuemap
- the map to be wrappedmap
public static <K,V> Map.Entry<K,V> entry(@Nullable K key, @Nullable V value)
Map.Entry
representing a mapping from the specified key to the
specified value.
This entry is immutable. It does not support the method
Map.Entry.setValue(Object)
.
K
- the type of the keyV
- the type of the valuekey
- the key represented by this entryvalue
- the value represented by this entrypublic static <K,V> Map<K,V> sort(Map<K,V> unsorted, Comparator<Map.Entry<K,V>> comparator)
Map
based on a given Map.Entry
Comparator
.
Currently returned map is implemented as LinkedHashMap
though that might change.
K
- the type of keys maintained by this mapV
- the type of mapped valuesunsorted
- probably unsorted mapcomparator
- entry based comparatorCopyright © 2025. All rights reserved.