Category Archives: Java 8

Join or concatenate or combine multiple strings in java (example)

1. Different methods to join or concatenate strings in java Join String using + operator Combine String using String concat method Contact String using String format Join String using StringBuilder format Join String using String join (Method included in java in JDK 1.8) We have already discussed Join Strings in java8 using StringJoiner. 2. Program –  Join or concat… Read More »

Primitive streams example in java8 (IntStream, LongStream, DoubleStream)

Java stream library have streams specifically for primitive types like int, long, double etc. With primitive streams, values are directly stored in primitives (not in wrapper classes like Integer, Long or Double). The rest of primitives like char, short, byte etc will make use existing streams like IntStream, LongStream and DoubleStream. 1. Create IntStream using… Read More »

Read a file line by line using java 8 lambda stream (example)

1. Read file using java 8 lambda stream Given a file, read input file by line by line using lambda stream in java 8. Get the input file (“readFile.txt”) from class path or some absolute location. We will use Java 7 feature try -with-resources, which will ensures that resources will be closed (automatically). Read the input… Read More »

Impact of interface’s default method on multiple inheritance (Java 8 /example)

Java 8 has introduced default method for interfaces, which provides the default implementation of method. Prior to java 8 interfaces does not have any default keyword There were no conflicts if class inherits multiple interfaces having same method (Prior to Java8). Example – multiple inheritance in java Let us take example to understand the multiple… Read More »

Java 8 Functional interface explained with examples (Comparator)

1. What is functional interface in java8? The interface having one abstract method is called functional interface. The interface can contains other default methods but needs to have one abstract method. The functional interface are generally marked with annotation “@FunctionalInterface”. Which signifies that they are functional interface. Having said that, It is not mandatory to… Read More »