Answers for "java find max value in list o(1)"

3

how to get the highest value in a list java

import java.util.*;
public class CollectionsMaxExample2 {
public static void main(String[] args) {
//Create collections lists.
List<Integer> list = Arrays.asList(20, 10, 100, 140, 250);
Integer max = Collections.max(list);
System.out.println("Maximum element is: "+max);
}
Posted by: Guest on January-08-2021
1

array find max in java

public static void main(String[] args) {
        int [] arr = {100,200,300,50,40,-10,-50};
        int max = Integer.MIN_VALUE;
        for(int each: arr)
            if(each > max)
                max = each;
        System.out.println(max); // 300
Posted by: Guest on June-09-2021
0

select max value from list java

List<Integer> list = new ArrayList<>();
        list.add(1);
        list.add(4);
        list.add(2);
        num = list.stream().mapToInt(Integer::intValue).max().getAsInt();
Posted by: Guest on October-05-2021

Code answers related to "java find max value in list o(1)"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language