Stream_collection
Wed Jun 05 2024 16:16:19 GMT+0000 (Coordinated Universal Time)
Saved by
@signup
import java.util.*;
import java.util.stream.*;
public class Main{
public static void main(String[] args)
{
ArrayList<Integer> al=new ArrayList<>();
al.add(7);
al.add(90);
al.add(4);
al.add(18);
al.add(3);
System.out.println("List : "+al);
Stream<Integer> stm=al.stream().filter(n->n%2==0);
stm.forEach(n->System.out.println(n+" "));
List<Integer> listeven=al.stream().filter(n->n%2==1).collect(Collectors.toList());
System.out.println("List even"+listeven);
Set<Integer> odd=al.stream().filter(n->n%2==1).collect(Collectors.toSet());
System.out.println("set odd"+odd);
}
}
content_copyCOPY
Comments