Longs Class | Guava | Java Last Updated : 29 May, 2018 Summarize Comments Improve Suggest changes Share Like Article Like Report 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 Longs Class : Some of the methods provided by Guava Longs Class are : Exceptions : min : IllegalArgumentException if array is empty. max : IllegalArgumentException if array is empty. fromByteArray : IllegalArgumentException if bytes has fewer than 8 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 Longs Class : Below given are some examples showing the implementation of methods of Guava Longs Class : Example 1 : Java // Java code to show implementation // of Guava Longs.asList() method import com.google.common.primitives.Longs; import java.util.*; class GFG { // Driver method public static void main(String[] args) { long arr[] = { 3L, 4L, 5L, 6L, 7L }; // Using Longs.asList() method which wraps // the primitive long array as List of // long Type List<Long> myList = Longs.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 Longs.toArray() method import com.google.common.primitives.Longs; import java.util.*; class GFG { // Driver method public static void main(String[] args) { List<Long> myList = Arrays.asList(3L, 4L, 5L, 6L, 7L); // Using Longs.toArray() method which // converts a List of Longs to an // array of long long[] arr = Longs.toArray(myList); // Displaying the elements System.out.println(Arrays.toString(arr)); } } Output : [3, 4, 5, 6, 7] Example 3 : Java // Java code to show implementation // of Guava Longs.concat() method import com.google.common.primitives.Longs; import java.util.*; class GFG { // Driver method public static void main(String[] args) { long[] arr1 = { 3L, 4L, 5L }; long[] arr2 = { 6L, 7L }; // Using Longs.concat() method which // combines arrays from specified // arrays into a single array long[] arr = Longs.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 Longs.contains() method import com.google.common.primitives.Longs; class GFG { // Driver method public static void main(String[] args) { long[] arr = { 3L, 4L, 5L, 6L }; // Using Longs.contains() method which // checks if element is present in array // or not System.out.println(Longs.contains(arr, 4L)); System.out.println(Longs.contains(arr, 7L)); } } output : true false Example 5 : Java // Java code to show implementation // of Guava Longs.min() method import com.google.common.primitives.Longs; class GFG { // Driver method public static void main(String[] args) { long[] arr = { 3L, 4L, 5L, 6L }; // Using Longs.min() method System.out.println(Longs.min(arr)); } } Output : 3 Example 6 : Java // Java code to show implementation // of Guava Longs.max() method import com.google.common.primitives.Longs; class GFG { // Driver method public static void main(String[] args) { long[] arr = { 3L, 4L, 5L, 6L }; // Using Longs.max() method System.out.println(Longs.max(arr)); } } Output : 6 Comment More infoAdvertise with us Next Article LongMath Class | Guava | Java S Sahil_Bansall Follow Improve Article Tags : Java Practice Tags : Java Similar Reads LongMath Class | Guava | Java LongMath is used to perform mathematical operations on Long values. Basic standalone math functions are divided into the classes IntMath, LongMath, DoubleMath, and BigIntegerMath based on the primary numeric type involved. These classes have parallel structure, but each supports only the relevant su 3 min read LongMath Class | Guava | Java LongMath is used to perform mathematical operations on Long values. Basic standalone math functions are divided into the classes IntMath, LongMath, DoubleMath, and BigIntegerMath based on the primary numeric type involved. These classes have parallel structure, but each supports only the relevant su 3 min read Range Class | Guava | Java Guavaâs Range represents an interval, for example, a < range < b. Here range includes any value between a and b, called endpoints which form the boundary. Any value between the boundary is a contiguous span of values of type Comparable. Declaration : The declaration for com.google.common.colle 5 min read Ordering Class | Guava | Java A comparator, with additional methods to support common operations. This is an "enriched" version of Comparator. The common ways to get an instance of Ordering are : Subclass it and implement compare(T, T) instead of implementing Comparator directly. Pass a pre-existing Comparator instance to from(C 4 min read Ordering Class | Guava | Java A comparator, with additional methods to support common operations. This is an "enriched" version of Comparator. The common ways to get an instance of Ordering are : Subclass it and implement compare(T, T) instead of implementing Comparator directly. Pass a pre-existing Comparator instance to from(C 4 min read Shorts Class | Guava | Java 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 Gu 3 min read Like