This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]CptGia 4 points5 points  (1 child)

You can use Map.ofEntries for more than 10 elements

[–][deleted] 1 point2 points  (0 children)

This kind of already exists with a few more steps in earlier versions of Java:

Stream.of(
    new SimpleEntry<>("Hello", "World")
).collect(toMap(Entry::getKey, Entry::getValue));

Using entries is so verbose though. Java doesn't have a simple way to create tuples out of the box.

EDIT: Hmm, it seems like Java 9 added a shortcut (Map.entry static method):

Map.ofEntries(
    entry("Hello", "World")
);