Guava - Floats Class - Guava

Floats is a utility class for primitive type float.

Class Declaration

Here’s the declaration for com.google.common.primitives.Floatsclass:

Fields

Sr.No

Field & Description

1

static int BYTES

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

Methods

Sr.No

Method & Description

1

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

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

2

static int compare(float a, float b)

Compares the two specified float values using Float.compare(float, float).

3

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

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

4

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

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

5

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.

6

static int hashCode(float value)

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

7

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

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

8

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.

9

static boolean isFinite(float value)

Returns true if value represents a real number.

10

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.

11

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

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

12

static Comparator<float[]> lexicographicalComparator()

Returns a comparator that compares two float arrays lexicographically.

13

static float max(float... array)

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

14

static float min(float... array)

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

15

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().

16

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().

17

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.
GuavaTester.java

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 © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

Guava Topics