Java Guava | Booleans.countTrue() method with Examples
Last Updated :
30 Jan, 2019
The countTrue() method of Booleans Class in Guava Library is used to count the number of values that are true in the specified boolean values passed as the parameter.
Syntax:
public static int countTrue(boolean... values)
Parameters: This method accepts the boolean values among which the true values are to be count.
Return values: This method returns an integer value which is the count of values that are true.
Example-1 :
import com.google.common.primitives.Booleans;
import java.util.Arrays;
class GFG {
public static void main(String[] args)
{
boolean [] arr = { false , true , false ,
true , true };
System.out.println(Booleans.countTrue(arr));
}
}
|
Example 2 :
import com.google.common.primitives.Booleans;
import java.util.Arrays;
class GFG {
public static void main(String[] args)
{
boolean [] arr = { false , false ,
false , false };
System.out.println(Booleans.countTrue(arr));
}
}
|
Reference: https://google.github.io/guava/releases/20.0/api/docs/com/google/common/primitives/Booleans.html#countTrue-boolean…-
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...