alternative
1) Given a list of integers, separate odd and even numbers?
                    
        import java.util.Arrays;
        import java.util.List;
        import java.util.Map;
        import java.util.stream.Collectors;

        public class Java8Questions {
            public static void main(String[] args) {
                List<Integer> listOfIntegers = Arrays.asList(2,5,3,1,6,9);
                Map<Boolean, List<Integer>> oddEvenNumbersMap = 
                        listOfIntegers.stream().collect(Collectors.partitioningBy(i -> i % 2 == 0));
                System.out.println(oddEvenNumbersMap);
            }
        }
                
Output

{false=[5, 3, 1, 9], true=[2, 6]}

2) How do you remove duplicate elements from a list of String using Java 8 streams?
                        
        import java.util.Arrays;
        import java.util.List;
        import java.util.stream.Collectors;
        
        public class Java8Questions {
            public static void main(String[] args) {
                List<String> listOfStrings = Arrays.asList("Code","Junction","Code","Innovation","Junction");
                List<String> uniqueStrngs = listOfStrings.stream().distinct().collect(Collectors.toList());
                System.out.println(uniqueStrngs);
            }
        }        
                
Output

[Code, Junction, Innovation]

3) How do you remove duplicate elements from a list of Integer using Java 8 streams?
                    
        import java.util.Arrays;
        import java.util.List;
        import java.util.stream.Collectors;
        
        public class Java8Questions {
            public static void main(String[] args) {
                List<Integer> listOfInt = Arrays.asList(2,5,3,2,1,6,5,9,4);
                List<Integer> uniqueVal = listOfInt.stream().distinct().collect(Collectors.toList());
                System.out.println(uniqueVal);
            }
        }
                
Output

[2, 5, 3, 1, 6, 9, 4]

4.How do you find frequency of each element in an array or a list?
                                
        import java.util.Arrays;
        import java.util.List;  
        import java.util.Map;
        import java.util.function.Function;
        import java.util.stream.Collectors;
        
        public class Java8Questions {
            public static void main(String[] args) {
                List<Integer> listOfInt = Arrays.asList(2,5,3,2,6,5,4);
                Map<Integer,Long> freqOfMap= listOfInt.stream()
                    .collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));
                System.out.println(freqOfMap);
            }
        }                        
                            
Output

{2=2, 3=1, 4=1, 5=2, 6=1}

                                
        import java.util.Arrays;
        import java.util.List;
        import java.util.Map;
        import java.util.function.Function;
        import java.util.stream.Collectors;
        
        public class Java8Questions {
            public static void main(String[] args) {
                List<String> stationeryList = Arrays.asList("Pen", "Eraser", "Pen", "Pencil", "Stapler", "Pencil");
                Map<String, Long> stationeryCountMap = stationeryList.stream()
                        .collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));
                System.out.println(stationeryCountMap);
            }
        }
                            
Output

{Pen=2, Stapler=1, Pencil=2, Eraser=1}

5) How do you find frequency of each character in a String?
                        
            import java.util.Map;
            import java.util.function.Function;
            import java.util.stream.Collectors;
            
            public class Java8Questions {
                public static void main(String[] args) {
                    String inputString="java";
                    Map stationeryCountMap = inputString.chars().mapToObj(c -> (char) c)
				        .collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));
                    System.out.println(stationeryCountMap);
                }
            }
                    
Output

{a=2, v=1, j=1}

6) How do you sort the list in reverse order?
                                
            import java.util.Arrays;
            import java.util.Collections;
            import java.util.List;
            import java.util.stream.Collectors;
            
            public class Java8Questions {
                public static void main(String[] args) {
                    List<Integer> listOfIntegers = Arrays.asList(2, 5, 3, 1, 6, 9);
                    List<Integer> sortedList = listOfIntegers.stream().sorted().collect(Collectors.toList());
                    List<Integer> reverseSortedList = listOfIntegers.stream().sorted(Collections.reverseOrder())
                            .collect(Collectors.toList());
                    System.out.println("Ascending Order:" + sortedList);
                    System.out.println("Decending Order:" + reverseSortedList);
                }                        
                            
Output

Ascending Order:[1, 2, 3, 5, 6, 9]

Decending Order:[9, 6, 5, 3, 2, 1]

                                
            import java.util.Arrays;
            import java.util.Collections;
            import java.util.List;
            import java.util.stream.Collectors;
            
            public class Java8Questions {
                public static void main(String[] args) {
                    List<String> listOfString = Arrays.asList("D","F","A","C","B");
                    List<String> sortedList = listOfString.stream().sorted().collect(Collectors.toList());
                    List<String> reverseSortedList = listOfString.stream().sorted(Collections.reverseOrder())
                            .collect(Collectors.toList());
                    System.out.println("Ascending Order:" + sortedList);
                    System.out.println("Decending Order:" + reverseSortedList);
                }               
            }                   
                            
Output

Ascending Order:[A, B, C, D, F]

Decending Order:[F, D, C, B, A]

BACK