10 Common Java Interview Questions Related to the Stream API
Java interview questions related to streams are often focused on practical usage of the Stream API introduced in Java 8. Some of the most common practical questions include: 1. Filtering a List Problem: Given a list of integers, filter out the even numbers and return a list of odd numbers. Solution: import java.util.Arrays ; import java.util.List ; import java.util.stream.Collectors ; public class Main { public static void main ( String [] args) { List < Integer > numbers = Arrays . asList ( 1 , 2 , 3 , 4 , 5 , 6 ); List < Integer > oddNumbers = numbers .stream() .filter(n -> n % 2 != 0 ) .collect( Collectors . toList ()); } } 2. Mapping a List Problem: Given a list of strings, convert all strings to uppercase. Solution: import java.util.Arrays ; import java.util.List ; import java.util.stream.Collectors ; public class Main { public static void main ( String [] args) { List < String > words =...