Shorts Class | Guava | Java Last Updated : 21 Nov, 2019 Comments Improve Suggest changes Like Article Like Report Shorts is a utility class for primitive type short. It provides Static utility methods pertaining to short primitives, that are not already found in either Short or Arrays. Declaration : @GwtCompatible(emulated=true) public final class Shorts extends Object Below table shows the Field summary for Guava Shorts Class : Some of the methods provided by Guava Shorts Class are : Exceptions : checkedCast : IllegalArgumentException if value is greater than Short.MAX_VALUE or less than Short.MIN_VALUE min : IllegalArgumentException if array is empty. max : IllegalArgumentException if array is empty. fromByteArray : IllegalArgumentException if bytes has fewer than 2 elements. ensureCapacity : IllegalArgumentException if minLength or padding is negative. toArray : NullPointerException if collection or any of its elements is null. Below table shows some other methods provided by Guava Shorts Class : Below given are some examples showing the implementation of Guava Shorts Class methods : Example 1 : Java // Java code to show implementation // of Guava Shorts.asList() method import com.google.common.primitives.Shorts; import java.util.*; class GFG { // Driver method public static void main(String[] args) { short arr[] = { 3, 4, 5, 6, 7 }; // Using Shorts.asList() method which convert // array of primitives to array of objects List<Short> myList = Shorts.asList(arr); // Displaying the elements System.out.println(myList); } } Output : [3, 4, 5, 6, 7] Example 2 : Java // Java code to show implementation // of Guava Shorts.indexOf() method import com.google.common.primitives.Shorts; import java.util.*; class GFG { // Driver method public static void main(String[] args) { short[] arr = { 3, 4, 5, 6, 7 }; // Displaying the index for // first occurrence of given target System.out.println(Shorts.indexOf(arr, (short)5)); } } Output : 2 Example 3 : Java // Java code to show implementation // of Guava Shorts.concat() method import com.google.common.primitives.Shorts; import java.util.*; class GFG { // Driver method public static void main(String[] args) { short[] arr1 = { 3, 4, 5 }; short[] arr2 = { 6, 7 }; // Using Shorts.concat() method which // combines arrays from specified // arrays into a single array short[] arr = Shorts.concat(arr1, arr2); // Displaying the elements System.out.println(Arrays.toString(arr)); } } Output : [3, 4, 5, 6, 7] Example 4 : Java // Java code to show implementation // of Guava Shorts.contains() method import com.google.common.primitives.Shorts; class GFG { // Driver method public static void main(String[] args) { short[] arr = { 3, 4, 5, 6, 7 }; // Using Shorts.contains() method which // checks if element is present in array // or not System.out.println(Shorts.contains(arr, (short)8)); System.out.println(Shorts.contains(arr, (short)7)); } } output : false true Example 5 : Java // Java code to show implementation // of Guava Shorts.min() method import com.google.common.primitives.Shorts; class GFG { // Driver method public static void main(String[] args) { short[] arr = { 3, 4, 5, 6, 7 }; // Using Shorts.min() method System.out.println(Shorts.min(arr)); } } Output : 3 Example 6 : Java // Java code to show implementation // of Guava Shorts.max() method import com.google.common.primitives.Shorts; class GFG { // Driver method public static void main(String[] args) { short[] arr = { 3, 4, 5, 6, 7 }; // Using Shorts.max() method System.out.println(Shorts.max(arr)); } } Output : 7 Comment More infoAdvertise with us Next Article Joiner class | Guava | Java S Sahil_Bansall Follow Improve Article Tags : Java Practice Tags : Java Similar Reads Longs Class | Guava | Java Longs is a utility class for primitive type long. It provides Static utility methods pertaining to long primitives, that are not already found in either Long or Arrays. Declaration : @GwtCompatible(emulated=true) public final class Longs extends Object Below table shows the Field summary for Guava L 3 min read Joiner class | Guava | Java Guava's Joiner class provides various methods to handle joining operations on string, objects, etc. This class provides advanced functionality for the join operation. Declaration: Following is the declaration for com.google.common.base.Joiner class : @GwtCompatible public class Joiner extends Object 2 min read Joiner class | Guava | Java Guava's Joiner class provides various methods to handle joining operations on string, objects, etc. This class provides advanced functionality for the join operation. Declaration: Following is the declaration for com.google.common.base.Joiner class : @GwtCompatible public class Joiner extends Object 2 min read Splitter Class | Guava | Java Guava's Splitter Class provides various methods to handle splitting operations on string, objects, etc. It extracts non-overlapping substrings from an input string, typically by recognizing appearances of a separator sequence. This separator can be specified as a single character, fixed string, regu 2 min read Splitter Class | Guava | Java Guava's Splitter Class provides various methods to handle splitting operations on string, objects, etc. It extracts non-overlapping substrings from an input string, typically by recognizing appearances of a separator sequence. This separator can be specified as a single character, fixed string, regu 2 min read Ints Class | Guava | Java Ints is a utility class for primitive type int. It provides Static utility methods pertaining to int primitives, that are not already found in either Integer or Arrays. Declaration : @GwtCompatible(emulated=true) public final class Ints extends Object Below table shows the Field summary for Guava In 3 min read Like