Doubles Class | Guava | Java
Last Updated :
29 May, 2018
Doubles is a utility class for primitive type
double. It provides
Static utility methods pertaining to double primitives, that are not already found in either Double or Arrays.
Declaration :
@GwtCompatible(emulated=true)
public final class Doubles
extends Object
Below table shows the Field summary for Guava Doubles Class :

Some of the methods provided by Guava Doubles Class are :
Exceptions :
- min : IllegalArgumentException if array is empty.
- max : IllegalArgumentException if array is empty.
- 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 Doubles Class :

Below given are some examples showing the implementation of Guava Doubles Class methods :
Example 1 :
Java
// Java code to show implementation
// of Guava Doubles.asList() method
import com.google.common.primitives.Doubles;
import java.util.*;
class GFG {
// Driver method
public static void main(String[] args)
{
double arr[] = { 2.6, 4.6, 1.2, 2.4, 1.5 };
// Using Doubles.asList() method which
// converts array of primitives to array of objects
List<Double> myList = Doubles.asList(arr);
// Displaying the elements
System.out.println(myList);
}
}
Output :
[2.6, 4.6, 1.2, 2.4, 1.5]
Example 2 :
Java
// Java code to show implementation
// of Guava Doubles.toArray() method
import com.google.common.primitives.Doubles;
import java.util.*;
class GFG {
// Driver method
public static void main(String[] args)
{
List<Double> myList = Arrays.asList(2.6, 4.6, 1.2, 2.4, 1.5);
// Using Doubles.toArray() method which
// converts a List of Doubles to an
// array of double
double[] arr = Doubles.toArray(myList);
// Displaying the elements
System.out.println(Arrays.toString(arr));
}
}
Output :
[2.6, 4.6, 1.2, 2.4, 1.5]
Example 3 :
Java
// Java code to show implementation
// of Guava Doubles.concat() method
import com.google.common.primitives.Doubles;
import java.util.*;
class GFG {
// Driver method
public static void main(String[] args)
{
double[] arr1 = { 2.6, 4.6, 1.2 };
double[] arr2 = { 2.4, 1.5 };
// Using Doubles.concat() method which
// combines arrays from specified
// arrays into a single array
double[] arr = Doubles.concat(arr1, arr2);
// Displaying the elements
System.out.println(Arrays.toString(arr));
}
}
Output :
[2.6, 4.6, 1.2, 2.4, 1.5]
Example 4 :
Java
// Java code to show implementation
// of Guava Doubles.contains() method
import com.google.common.primitives.Doubles;
class GFG {
// Driver method
public static void main(String[] args)
{
double[] arr = { 2.6, 4.6, 1.2, 2.4, 1.5 };
// Using Doubles.contains() method which
// checks if element is present in array
// or not
System.out.println(Doubles.contains(arr, 2.5));
System.out.println(Doubles.contains(arr, 1.5));
}
}
output :
false
true
Example 5 :
Java
// Java code to show implementation
// of Guava Doubles.min() method
import com.google.common.primitives.Doubles;
class GFG {
// Driver method
public static void main(String[] args)
{
double[] arr = { 2.6, 4.6, 1.2, 2.4, 1.5 };
// Using Doubles.min() method
System.out.println(Doubles.min(arr));
}
}
Output :
1.2
Example 6 :
Java
// Java code to show implementation
// of Guava Doubles.max() method
import com.google.common.primitives.Doubles;
class GFG {
// Driver method
public static void main(String[] args)
{
double[] arr = { 2.6, 4.6, 1.2, 2.4, 1.5 };
// Using Doubles.max() method
System.out.println(Doubles.max(arr));
}
}
Output :
4.6
Similar Reads
Floats Class | Guava | Java Floats is a utility class for primitive type float. It provides Static utility methods pertaining to float primitives, that are not already found in either Float or Arrays. Declaration : @GwtCompatible(emulated=true) public final class Floats extends Object Below table shows the Field summary for Gu
3 min read
Java.Lang.Double Class in Java Double class is a wrapper class for the primitive type double which contains several methods to effectively deal with a double value like converting it to a string representation, and vice-versa. An object of the Double class can hold a single double value. Double class is a wrapper class for the pr
4 min read
Chars Class | Guava | Java Chars is a utility class for primitive type char. It provides Static utility methods pertaining to char primitives, that are not already found in either Character or Arrays. All the operations in this class treat char values strictly numerically, i.e, they are neither Unicode-aware nor locale-depend
3 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
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
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