Java interview question: In Java 8 count frequency of chars in a String. In this post we’ll show two implementations – using Map.merge() and Streams and Collectors.
Continue reading Java 8 count frequency of chars in Stringjava-util
In Java 8 count frequency of numbers/elements/objects. You may encounter this problem on Java job interviews. Here we implement it using Java 8 Collectors.
Continue reading Java 8 count frequency of numbers/elements/objectsVery common task is creation of Map from a List of objects. In this post we show how to use Java 8 to convert List to Map using Collectors.
Continue reading Java 8 List to MapIn this article we present Java 8 forEach on examples. These are very convenient methods for use with Lambda Expressions and method references.
Continue reading Java 8 forEach examplesIt’s very common task in Java to format double to 2 decimal places – usually to format currency. It’s not easy to do correctly, but in this post we’ll show how.
Continue reading Java format double 2 decimal places – currency formattingJava 8 reduce is a great method to compute a value from stream of values – reduce collection to value. In this post we’ll explain how reduce in Java work.
Continue reading Java 8 reduce by examplejava.util.Optional.map(Function) The method Optional.map(Function) applies the given function to the optional value if it is present and returns an optional with the result or empty optional.
Continue reading Java Util Optional map(Function)java.util.Optional.ofNullable(T) The method Optional.ofNullable(T) returns Optional containing given value if it was not null or an empty Optional in case of null value.
Continue reading Java Util Optional.ofNullable(T)java.util.Map.replaceAll(BiFunction) The method Map.replaceAll(BiFunction) replaces each value with the result of applying the given function on the corresponding entry. Rethrows exceptions thrown by the replacement function.
Continue reading Java Util Map replaceAll(BiFunction)java.util.Map.replace(key, oldValue, newValue) The method Map.replace(key, oldValue, newValue) replaces the value associated with the given key only if it is currently mapped to the oldValue.
Continue reading Java Util Map replace(key, oldValue, newValue)