

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Find minimum element of ArrayList with Java Collections
In order to compute minimum element of ArrayList with Java Collections, we use the Collections.min() method. The java.util.Collections.min() returns the minimum element of the given collection. All elements must be mutually comparable and implement the comparable interface. They shouldn’t throw a ClassCastException.
Declaration −The Collections.min() method is declared as follows −
public static <T extends Object & Comparable> T min(Collection c)
where c is the collection object whose minimum is to be found.
Let us see a program to find the minimum element of ArrayList with Java collections −
Example
import java.util.*; public class Example { public static void main (String[] args) { List<Integer> list = new ArrayList<Integer>(); try { list.add(14); list.add(2); list.add(73); System.out.println("Minimum element : " + Collections.min(list)); } catch (ClassCastException | NoSuchElementException e) { System.out.println("Exception caught : " + e); } } }
Output
Minimum element : 2
- Related Questions & Answers
- Find maximum element of ArrayList with Java Collections
- Replace all occurrences of specified element of ArrayList with Java Collections
- Shuffle elements of ArrayList with Java Collections
- Swap elements of ArrayList with Java collections
- Replace All Elements Of ArrayList with with Java Collections
- Get Enumeration over ArrayList with Java Collections
- Copy Elements of One ArrayList to Another ArrayList with Java Collections Class
- Reverse order of all elements of ArrayList with Java Collections
- Perform Binary Search on ArrayList with Java Collections
- Sort ArrayList in Descending order using Comparator with Java Collections
- Find minimum element of HashSet in Java
- Find the minimum element of a Vector in Java
- Search an element of ArrayList in Java
- Java Lambda Expression with Collections
- Check existence of an element in Java ArrayList
Advertisements