0 votes
396 views
in Java by
How will you find the highest number in list by using Java 8?

1 Answer

0 votes
by (5k points)
See the following running code to print highest number in list by using java 8:-

package com.java8.array;

import java.util.Arrays;
import java.util.List;
import java.util.NoSuchElementException;

public class HeighestNumberInList {

    public static void main(String[] args) {

        List<Integer> integers = Arrays.asList(1, 2, 83, 4, 56, 7, 89, 10);
     
        Integer max = integers.stream()
                              .mapToInt(v -> v)
                              .max().
                              orElseThrow(NoSuchElementException::new);
        System.out.println("Max Interger value: "+max);
    }

}
Output:-
Max Interger value: 89

Share:- Whatsapp Facebook Facebook


Welcome to Developerhelpway Q&A, where you can ask questions and receive answers from other members of the community.

Categories

...