Java Guava | Booleans.countTrue() method with Examples
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 :
// Java code to show implementation of // Guava's Booleans.countTrue() method import com.google.common.primitives.Booleans; import java.util.Arrays; class GFG { // Driver's code public static void main(String[] args) { // Creating a Boolean array boolean[] arr = { false, true, false, true, true }; // Using Booleans.countTrue() method to // get the number of values that are true System.out.println(Booleans.countTrue(arr)); } } |
3
Example 2 :
// Java code to show implementation of // Guava's Booleans.countTrue() method import com.google.common.primitives.Booleans; import java.util.Arrays; class GFG { // Driver's code public static void main(String[] args) { // Creating a Boolean array boolean[] arr = { false, false, false, false }; // Using Booleans.countTrue() method to // get the number of values that are true System.out.println(Booleans.countTrue(arr)); } } |
0
Recommended Posts:
- Java Guava | Longs.min() method with Examples
- Java Guava | Doubles.min() method with Examples
- Java Guava | Bytes.contains() method with Examples
- Java Guava | Doubles.contains() method with Examples
- Java Guava | Floats.contains() method with Examples
- Java Guava | Shorts.min() method with Examples
- Java Guava | Chars.contains() method with Examples
- Java Guava | Floats.max() method with Examples
- Java Guava | Floats.min() method with Examples
- Java Guava | Longs.max() method with Examples
- Java Guava | Doubles.max() method with Examples
- Java Guava | Longs.contains() method with Examples
- Java Guava | Chars.max() method with Examples
- Java Guava | Booleans.contains() method with Examples
- Java Guava | Chars.min() method with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



