Java 8 Find Max Value
public class Test {
public static void main(String args[])
{
List<Student> list = new ArrayList<>();
Student student1 = new Student(1, 20, "A");
Student student2 = new Student(2, 35, "A");
Student student3 = new Student(3, 25, "A");
list.add(student1);
list.add(student2);
list.add(student3);
OptionalInt maxValue = list.stream().mapToInt(student->student.getAge()).max();
System.out.print("Max Value-->"+maxValue.getAsInt());
List<Integer> list = List.of(1,2,3,4,5,6,7,8);}
OptionalInt maxValue = list.stream().mapToInt(x->x).max();
System.out.print("Max Value-->"+maxValue.getAsInt());
}
Comments
Post a Comment