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 101 views
1 answer 124 views
1 answer 221 views
1 answer 169 views
1 answer 114 views
1 answer 120 views
2 answers 248 views
...