How to find the largest number in an ArrayList with Java

1 Answer

0 votes
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;

public class MyClass {
    public static void main(String args[]) {
        ArrayList<Integer> al = new ArrayList<Integer>(Arrays.asList(5, 2, 9, 7, 5, 1));
        
        int max = Collections.max(al);

        System.out.println(max);
    }
}
 
 
 
/*
run:
 
9
 
*/

 



answered Mar 22, 2021 by avibootz

Related questions

2 answers 105 views
1 answer 132 views
1 answer 233 views
1 answer 182 views
1 answer 120 views
1 answer 126 views
2 answers 260 views
...