Guava - Floats Class - Guava

Floats is a utility class for primitive type float.

Class Declaration

Here’s the declaration for



Field & Description


static int BYTES

The number of bytes required to represent a primitive float value.



Method & Description


static List<Float> asList(float... backingArray)

Returns a fixed-size list backed by the specified array, similar to Arrays.asList(Object[]).


static int compare(float a, float b)

Compares the two specified float values using, float).


static float[] concat(float[]... arrays)

Returns the values from each provided array combined into a single array.


static boolean contains(float[] array, float target)

Returns true if target is present as an element anywhere in array.


static float[] ensureCapacity(float[] array, int minLength, int padding)

Returns an array containing the same values as the array, but guaranteed to be of a specified minimum length.


static int hashCode(float value)

Returns a hash code for value; equal to the result of invoking ((Float) value).hashCode().


static int indexOf(float[] array, float target)

Returns the index of the first appearance of the value target in array.


static int indexOf(float[] array, float[] target)

Returns the start position of the first occurrence of the specified target within array, or -1 if there is no such occurrence.


static boolean isFinite(float value)

Returns true if value represents a real number.


static String join(String separator, float... array)

Returns a string containing the supplied float values, converted to strings as specified by Float.toString(float), and separated by separator.


static int lastIndexOf(float[] array, float target)

Returns the index of the last appearance of the value target in array.


static Comparator<float[]> lexicographicalComparator()

Returns a comparator that compares two float arrays lexicographically.


static float max(float... array)

Returns the greatest value present in array, using the same rules of comparison as Math.min(float, float).


static float min(float... array)

Returns the least value present in array, using the same rules of comparison as Math.min(float, float).


static Converter<String,Float> stringConverter()

Returns a serializable converter object that converts between strings and floats using Float.valueOf(java.lang.String) and Float.toString().


static float[] toArray(Collection<? extends Number> collection)

Returns an array containing each value of collection, converted to a float value in the manner of Number.floatValue().


static Float tryParse(String string)

Parses the specified string as a single-precision floating point value.

Methods Inherited

This class inherits methods from the following class:
  • java.lang.Object

Example of Floats class

Create the following java program using any editor of your choice in say C:/> Guava.

Verify the Result

Compile the class using javac compiler as follows:
Now run the GuavaTester to see the result.
See the result.

All rights reserved © 2020 Wisdom IT Services India Pvt. Ltd Protection Status

Guava Topics