Java Guava | Floats.min() method with Examples
Last Updated :
30 Jan, 2019
Floats.min() is a method of Floats Class in Guava library which is used to find the least value present in an array. The value returned by this method is the smallest float value in the specified array.
Syntax:
public static float min(float... array)
Parameters: This method takes a mandatory parameter array which is a nonempty array of float values.
Return Value: This method returns a float value that is the minimum value in the specified array.
Exceptions: The method throws IllegalArgumentException if the array is empty.
Below programs illustrate the use of the above method:
Example 1 :
import com.google.common.primitives.Floats;
import java.util.Arrays;
class GFG {
public static void main(String[] args)
{
float [] arr = { 2 .2f, 4 .3f, 6 .4f, 10 .5f,
0 .6f, - 5 .7f, 15 .8f };
System.out.println( "Minimum Value is : "
+ Floats.min(arr));
}
}
|
Output:
Minimum Value is : -5.7
Example 2:
import com.google.common.primitives.Floats;
import java.util.Arrays;
class GFG {
public static void main(String[] args)
{
float [] arr = {};
try {
System.out.println( "Minimum Value is : "
+ Floats.min(arr));
}
catch (Exception e) {
System.out.println(e);
}
}
}
|
Output:
java.lang.IllegalArgumentException
Reference: https://google.github.io/guava/releases/19.0/api/docs/com/google/common/primitives/Floats.html#min(float…)
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...