-
Notifications
You must be signed in to change notification settings - Fork 0
/
FindMaximumOfArrayListExample.java
42 lines (32 loc) · 1.07 KB
/
FindMaximumOfArrayListExample.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package ArrayList;
/*
Find maxmimum element of Java ArrayList Example
This java example shows how to find a maximum element of Java ArrayList using
max method of Collections class.
*/
import java.util.ArrayList;
import java.util.Collections;
public class FindMaximumOfArrayListExample {
public static void main(String[] args) {
//create an ArrayList object
ArrayList arrayList = new ArrayList();
//Add elements to Arraylist
arrayList.add(new Integer("327482"));
arrayList.add(new Integer("13408"));
arrayList.add(new Integer("802348"));
arrayList.add(new Integer("345308"));
arrayList.add(new Integer("509324"));
/*
To find maximum element of Java ArrayList use,
static Object max(Collection c) method of Collections class.
This method returns the maximum element of Java ArrayList according to
its natural ordering.
*/
Object obj = Collections.max(arrayList);
System.out.println("Maximum Element of Java ArrayList is : " + obj);
}
}
/*
Output would be
Maximum Element of Java ArrayList is : 802348
*/