Is there any way that I can put a whole Entry
object to a Map
object like:
map.put(entry);
instead of passing a k
To instantiate a Map with Entries (in the same way as you can do Arrays.asList(T... a)
or Sets.newHashSet(T... a)
in Google Guava library, I found this:
import java.util.AbstractMap;
import java.util.Map;
public class MapWithEntries {
private static final Map.Entry ENTRY_1 = new AbstractMap.SimpleEntry<>("A", "Hello");
private static final Map.Entry ENTRY_2 = new AbstractMap.SimpleEntry<>("B", "World");
private static final Map MAP_WITH_ENTRIES = Map.ofEntries(ENTRY_1, ENTRY_2);
}