Find maximum element in a List
import java.util.ArrayList;
import java.util.Collections;
public class Main {
public static void main(String[] args) {
ArrayList<Integer> arrayList = new ArrayList<Integer>();
arrayList.add(new Integer("3"));
arrayList.add(new Integer("1"));
arrayList.add(new Integer("8"));
arrayList.add(new Integer("3"));
arrayList.add(new Integer("5"));
Object obj = Collections.max(arrayList);
System.out.println(obj);
}
}
Output:
8
Home
Java Book
Runnable examples
Java Book
Runnable examples
Collection List:
- Create a list from an array
- Add element to a list at specified index
- Append one list to another list
- Insert a list at Specified Index
- Compare two List objects
- Convert Collection to List
- Convert a Queue to a List
- Convert List to array
- Convert List to a Set
- Copy List to Vector
- Copy one List to Another List
- Fill all elements in a list
- Fill n Copies of Specified Object
- Find maximum element in a List
- Find Minimum element in a List
- Get element by index
- Get Enumeration over List
- Get Synchronized List from a List
- Get Sub List
- Loop a list by Iterator
- Loop a list by generic Iterator
- Loop a list with using ListIterator
- Loop through a ist in reverse direction using ListIterator
- Remove an element by value and by index from List
- Remove all elements from a List
- Remove duplicate items from a List
- Remove item from a List while looping
- Remove range of elements from a List
- Remove user object from a list
- Replace an Element of List
- Replace all occurrences of specified element in a List
- Replace an element in a List using ListIterator
- Reverse a List
- Reverse order of all elements in a List
- Rotate elements of a list
- Search a List for an item with contains method
- Search elements of a List
- Binary Search a Sorted List
- Binary Search for a non-existent element in a List
- Set to change(replace) the value in a list
- Shuffle elements in a List
- Shuffle(repeatable) a List
- Sort a list
- Sort a List in descending order using comparator
- Swap elements of List