Wednesday, 8 November 2023

Java Stream Max

1) Find Maximum number in Array list

import java.util.ArrayList;
import java.util.List;

public class javaStreamExamples {
    List<Integer> list1=Arrays.asList(10,20,35,20,67,10)

    public void testStream(){
        Int max1=list1.stream().max(Integer:: compare).get();

System.out.println(max1);

    }

}

O/p
67


≠=================================

1) Find Minimum number in Array list

import java.util.ArrayList;
import java.util.List;

public class javaStreamExamples {
    List<Integer> list1=Arrays.asList(10,20,35,20,67,10)

    public void testStream(){
        Int min1=list1.stream().max(Comparator.reverseOrder()).get();

System.out.println(min1);

    }

}

O/p
67


≠=================================


No comments:

Post a Comment