Java Streams and IDE Weirdness (part 2)

ImmutableMap<String, String> sourceMap = ImmutableMap.of("key1", "value1",
"key2", "value2");
ImmutableMap<String, String> destMap = sourceMap.entrySet()
.stream()
.collect(Collectors.toMap(
Map.Entry::getKey,
Map.Entry::getValue
));
ImmutableMap<String, String> destMap = sourceMap.entrySet()
.stream()
.collect(ImmutableMap.toImmutableMap(Map.Entry::getKey, Map.Entry::getValue));
  1. Anytime you see this many generics in a javadoc slow way down to make sure you understand what’s happening public static <T,K,V> Collector <T,?,ImmutableMap<K,V>>
  2. Use as specific of a stream collector as you can
  3. When in doubt (or extreme need) revert to a good ol’ for loop

--

--

--

Engineer, formerly at Amazon, currently at Google. All opinions are my own. Consider supporting here: https://devblabs.medium.com/membership

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Handling Packages In Python

How to configure the client & server certificates in nginx

Parsing Huge XLSX files in fastest possible way?

How make your computer speak using Amazon Polly

SVTMedia https://t.co/RBXIcKD6ZF for following us on Twitter!

Syntactic Sugar, Spice, and Everything Nice

#Day 0 Preparing the journey

Download a FREE Header & Footer for Divi’s Pizzeria Layout Pack

19coders

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Brian Olson

Brian Olson

Engineer, formerly at Amazon, currently at Google. All opinions are my own. Consider supporting here: https://devblabs.medium.com/membership

More from Medium

Java Reactive Programming: Something Old, Something New

Spring explained: What is Spring? And what is Spring Boot?

Easy way to set your Java Home

Java ClassLoader Subsystem and how it works internally