Java Guava | Shorts.max() method with Examples Last Updated : 11 Jul, 2025 Comments Improve Suggest changes Like Article Like Report Shorts.max() is a method of Shorts class in Guava library which is used to find the greatest value present in an array. The value returned by this method is the largest short value in the specified array. Syntax: public static short max(short... array) Parameters: This method takes a mandatory parameter array is a nonempty array of short values. Return Value:This method returns a short value that is the maximum value in the specified array. Exceptions:The method throws IllegalArgumentException if the array is empty. Below programs illustrate the use of the above method: Example-1 : Java // Java code to show implementation of // Guava's Shorts.max() method import com.google.common.primitives.Shorts; import java.util.Arrays; class GFG { // Driver's code public static void main(String[] args) { // Creating a short array short[] arr = { 2, 4, 6, 10, 0, -5, 15, 7 }; // Using Shorts.max() method to get the // maximum value present in the array System.out.println("Maximum value is : " + Shorts.max(arr)); } } Output: Maximum value is : 15 Example-2 : Java // Java code to show implementation of // Guava's Shorts.max() method import com.google.common.primitives.Shorts; import java.util.Arrays; class GFG { // Driver's code public static void main(String[] args) { // Creating a short array short[] arr = {}; // Using Shorts.max() method to get the // maximum value present in the array // This should raise "IllegalArgumentException" // as the array is empty System.out.println("Maximum value is : " + Shorts.max(arr)); } } Output: Exception in thread "main" java.lang.IllegalArgumentException at com.google.common.base.Preconditions.checkArgument(Preconditions.java:108) at com.google.common.primitives.Shorts.max(Shorts.java:254) at GFG.main(File.java:19) Reference https://guava.dev/releases/23.0/api/docs/com/google/common/primitives/Shorts.html#max-short...- Comment More infoAdvertise with us Next Article Java Guava | Shorts.min() method with Examples S Sahil_Bansall Follow Improve Article Tags : Java java-guava Guava-Shorts Practice Tags : Java Similar Reads Java Guava | Shorts.min() method with Examples Shorts.min() method of Guava's Shorts Class is used to find the least value present in an array. The value returned by this method is the smallest short value in the specified array. Syntax: public static short min(short... array) Parameters: This method takes a mandatory parameter array which is a 2 min read Java Guava | Shorts.min() method with Examples Shorts.min() method of Guava's Shorts Class is used to find the least value present in an array. The value returned by this method is the smallest short value in the specified array. Syntax: public static short min(short... array) Parameters: This method takes a mandatory parameter array which is a 2 min read Java Guava | Shorts.toArray() method with Examples The toArray() method of Shorts Class in the Guava library is used to convert the short values, passed as the parameter to this method, into a Short Array. These short values are passed as a Collection to this method. This method returns a Short array. Syntax: public static short[] toArray(Collection 2 min read Java Guava | Shorts.toArray() method with Examples The toArray() method of Shorts Class in the Guava library is used to convert the short values, passed as the parameter to this method, into a Short Array. These short values are passed as a Collection to this method. This method returns a Short array. Syntax: public static short[] toArray(Collection 2 min read Java Guava | Shorts.hashCode() method with Examples Shorts.hashCode() is a method of Shorts Class in Guava Library which is used to return a hash code for a short value. The hashCode is an unique integer value that is calculated by the compiler for an object. It remain the same if the object value does not changes. Syntax: public static int hashCode( 2 min read Java Guava | Shorts.hashCode() method with Examples Shorts.hashCode() is a method of Shorts Class in Guava Library which is used to return a hash code for a short value. The hashCode is an unique integer value that is calculated by the compiler for an object. It remain the same if the object value does not changes. Syntax: public static int hashCode( 2 min read Like