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 :
import com.google.common.primitives.Longs;
import java.util.*;
class GFG {
public static void main(String[] args)
{
long arr[] = { 3L, 4L, 5L, 6L, 7L };
List<Long> myList = Longs.asList(arr);
System.out.println(myList);
}
}
|
Output :
[3, 4, 5, 6, 7]
Example 2 :
import com.google.common.primitives.Longs;
import java.util.*;
class GFG {
public static void main(String[] args)
{
List<Long> myList = Arrays.asList(3L, 4L, 5L, 6L, 7L);
long [] arr = Longs.toArray(myList);
System.out.println(Arrays.toString(arr));
}
}
|
Output :
[3, 4, 5, 6, 7]
Example 3 :
import com.google.common.primitives.Longs;
import java.util.*;
class GFG {
public static void main(String[] args)
{
long [] arr1 = { 3L, 4L, 5L };
long [] arr2 = { 6L, 7L };
long [] arr = Longs.concat(arr1, arr2);
System.out.println(Arrays.toString(arr));
}
}
|
Output :
[3, 4, 5, 6, 7]
Example 4 :
import com.google.common.primitives.Longs;
class GFG {
public static void main(String[] args)
{
long [] arr = { 3L, 4L, 5L, 6L };
System.out.println(Longs.contains(arr, 4L));
System.out.println(Longs.contains(arr, 7L));
}
}
|
output :
true
false
Example 5 :
import com.google.common.primitives.Longs;
class GFG {
public static void main(String[] args)
{
long [] arr = { 3L, 4L, 5L, 6L };
System.out.println(Longs.min(arr));
}
}
|
Output :
3
Example 6 :
import com.google.common.primitives.Longs;
class GFG {
public static void main(String[] args)
{
long [] arr = { 3L, 4L, 5L, 6L };
System.out.println(Longs.max(arr));
}
}
|
Output :
6