Description
max(Collection<? extends T>) Method is used to return the largest element of a given set according to the natural order of its elements.
Manifesto
The following is the declaration of the Java. Util. Collections. Max () method.
public static <T extends Object & Comparable<?super T>> T max(Collection<?extends T> coll)
Parameters
coll – The set whose largest element is to be determined.
Return value
Method call returns the largest element of a given collection, according to the natural order of its elements.
Exception
ClassCastException – This exception is thrown if the collection contains elements that are not comparable to each other, such as strings and integers. NoSuchElementException – If the collection is empty, this exception is thrown.
example
The following example shows the usage of Java. Util. Collections. Max()
import java.util.*;
public class CollectionsDemo {
public static void main(String args[]) {
// create link list object
LinkedList<Integer> list = new LinkedList<Integer>();
// populate the list
list.add(-18);
list.add(40);
list.add(-45);
list.add(12);
System.out.println("Max value is: " + Collections.max(list));
}
}
Let’s compile and run the above program, which will produce the following result.
Max value is: 40
Read More:
- java.lang.NoSuchMethodError: org.json.JSONObject.put(Java/lang/String; Java/util/Collection;) “209151;”
- android Caused by: java.util.ConcurrentModificationException
- Error querying database. Cause: java.util.ConcurrentModificationException
- solve java.util.prefs . backingstoreexception error
- No converter found capable of converting from type [java.lang.String] to type [java.util.Map<java.la
- Failed to convert value of type ‘java.lang.String‘ to required type ‘java.util.Date‘;
- errorCode:9015,errorMsg:cn.bmob.v3.util.BmobContentProvider.updateProvider(BmobContentProvider.java:
- Net Q & A: how to avoid the exception thrown by max() on emptyenumerable?
- The command Du – h — max depth = 1 in Linux
- Max must be larger than min in range parameter
- Syntax error or access violation: 1071 specified key was too long; max key length is 767 bytes
- Cannot find module ‘internal / util / types’ appears during gulp build
- NPM error ‘cannot find module’ internal / util / types’ solution;
- Create a new project in pycharm: modulenotfounde rror:No module named ‘distutils.util‘
- [Solved] IE Browser Upload Files Error: org.apache.tomcat.util.http.fileupload.FileUploadException: Stream ended unexpectedly
- After installing nodejs, run NPM on the command line and report error: cannot find module ‘internal / util / types’
- [BUG-mybatis-plus] org.postgresql.util.PSQLException: ERROR: syntax error at or near “current_date“
- Error: Could not find or load main class org.apache.hadoop.hbase.util.HBaseConfTool
- Error in idea compilation: java.lang.OutOfMemoryError Java heap space and java.lang.StackOverflowError
- Java:java.lang.OutOfMemoryError : GC overhead limit exceeded solution