I have a Map<Float, String>
and would like to get the maximum of all keys. In C# I would do something like this:
var dictionary = new Dictionary<float, string>{{5,"foo"}, {42, "bar"}, {0, "foobarz"}};
float max = dictionary.Max(x => x.Key); //42
Now I'm looking for a way to do the same using Java 8 lambdas, but the closest I got is:
float max = (float)map.keySet().stream().mapToDouble((x) -> x).summaryStatistics().getMax();
This looks awful and requires completely unnecessary type casts. Is there a better way to do this?