Hello @Kartik,
In plain java 8 you also have the possibility of using Streams/Collectors to do the job.
Map<String, String> myMap = Stream.of(
new SimpleEntry<>("key1", "value1"),
new SimpleEntry<>("key2", "value2"),
new SimpleEntry<>("key3", "value3"))
.collect(toMap(SimpleEntry::getKey, SimpleEntry::getValue));
This has the advantage of not creating an Anonymous class.
Note that the imports are:
import static java.util.stream.Collectors.toMap;
import java.util.AbstractMap.SimpleEntry;
Note: In java 9 onwards you have simpler ways of doing the same.
Hope this is helpfull!!
Thank You!!