In this Page contains Most important coding question related to Java 8. There are lots of new features added in Java 8 which has also changed some syntax.
If you are working on old Java then you should practice the lot of program to accept the changes made in Java 8. Also during interview, Interviewer will surely ask you to write some program on Java 8.
So to clear coding round or to solve the coding question asked you to write in Java 8, you should also prepare for writing the code.
Java 8 coding interview questions
Q1). Java 8 Program to add prefix and suffix to the String?
Ans:
To write a program in java to add prefix and suffix in a given String we will use StringJoiner class, a newly added in Java 8.
In the below program We will be adding “#“ and “#” as a prefix and suffix in the string.
Program
Output

Q2). Java 8 Program to Print ten random numbers using forEach?
Ans:
Below is the program to generate 10 random number using forEach. Here we are using Random class to generate Random number.
Program
Output

Q3). Java 8 program to iterate a Stream using the forEach method?
Ans:
In the below program we have create a List of array type. And We are iterating this using forEach after converting into stream.
Program to iterate stream using forEach in java 8
Output

Q4). Java 8 program to find the Minimum number of a Stream?
Ans:
To find the minimum number in stream, we will use comparator.comparing() method which will take integer value from Stream.
Below is the program to find minimum in Stream.
Program
Output

Q5). Java 8 program to find the Maximum number of a Stream?
Ans:
To find the Maximum number in stream, we will use comparator.comparing() method which will take integer value from Stream.
Below is the program to find Maximum in Stream.
Program
Output

Q6) Java 8 program to Count Strings whose length is greater than 3 in List?
Ans:
Below is the program where we have created a String List. We will be using filter and count function of java 8 to identify the string whose length is greater than 3.
Program
Output

Q7). Java 8 program to Print Strings whose length is greater than 3 in List.
Ans :
Program
Output

Q8) Java 8 program to multiply 3 to all elements in the list and print the list?
Ans:
To perform a multiply of 3 on each element of the list we will use the map() function. This function will perform the operation and will generate a new stream with updated value.
Program
Output

Q9) Java 8 program to perform concatenation on two Streams?
Ans:
To Perform concatenation on two stream, first we will create two stream and using concat function we will perform string concatenation.
Program to concatenate two Streams
Output

Q10) Java 8 program to remove the duplicate elements from the list?
Ans:
To remove duplicate element form list we have used Collectors.toSet(). As we know that set can have only unique value, we are converting our list to set so that we can have only unique value.
Program
Output

Q11) Print current date and time in Java 8 Date and Time API?
Ans:To get current date and time we are using LocalDate, LocalTime, and LocalDateTime API provided in java 8.
Program
Output

Q12) Java 8 program to sort the given list?
Ans:To Sort the integer element given in List, we will use sorted() method which will sort the List elements.
Program

Q13). Write a Java 8 program to get the sum of all numbers present in a list?
Ans: Program
Output

Q14) Java 8 program to perfrom cube on list elements and filter numbers greater than 50.
Ans:
Program
Output
