Posts

Showing posts from 2026

Java 8 stream API coding questions

 import java.util.*; import java.util.stream.Collectors; import java.util.function.Function; import java.util.stream.*; import java.time.*; public class Main {     public static void main(String[] args) {              //seperate odd and even       List<Integer> list = Arrays.asList(1,4,7,8,0,9,3);         List<Integer> odd=  list.stream()      .filter(x->x%2==1)      .collect(Collectors.toList());      List<Integer> even = list.stream().filter(x->x%2==0).collect(Collectors.toList());     //using partioning By  Map<Boolean,List<Integer>> sep = list.stream().collect(Collectors.partitioningBy(x->x%2==0));       System.out.println("odd :"+ odd + "even:"+even );       System.out.println("odd: "+ sep.get(true));       System.out.println("even: "+ sep.ge...