The nextBoolean() method of Random class returns the next pseudorandom, uniformly distributed boolean value from the random number generator’s sequence.
Syntax:
public boolean nextBoolean()
Parameters: The function does not accepts any parameter.
Return Value: This method returns the next pseudorandom, uniformly distributed boolean value.
Exception: The function does not throws any exception.
Program below demonstrates the above mentioned function:
Program 1:
// program to demonstrate the // function java.util.Random.nextBoolean() import java.util.*; public class GFG { public static void main(String[] args) { // create random object Random random = new Random(); // get boolean value System.out.println("Random boolean value is : " + random.nextBoolean()); } } |
Random boolean value is : true
Program 2:
// program to demonstrate the // function java.util.Random.nextBoolean() import java.util.*; public class GFG { public static void main(String[] args) { // create random object Random random = new Random(); // get boolean value System.out.println("Random boolean value is : " + random.nextBoolean()); } } |
Random boolean value is : false
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
Recommended Posts:
- Scanner nextBoolean() method in Java with Examples
- Random next() method in Java with Examples
- Java Math random() method with Examples
- Random setSeed() method in Java with Examples
- Random nextGaussian() method in Java with Examples
- Random nextFloat() method in Java with Examples
- Random nextLong() method in Java with Examples
- Random nextBytes() method in Java with Examples
- Random nextDouble() method in Java with Examples
- StrictMath random() Method in Java
- Random vs Secure Random numbers in Java
- Java lang.Long.numberOfTrailingZeros() method in Java with Examples
- Java lang.Long.byteValue() method in Java with Examples
- Java lang.Long.reverse() method in Java with Examples
- Java.util.Collections.disjoint() Method in java with Examples
- Java lang.Long.builtcount() method in Java with Examples
- Java.util.Collections.rotate() Method in Java with Examples
- Java lang.Long.highestOneBit() method in Java with Examples
- Java.lang.Short toString() method in Java with Examples
- Java lang.Long.lowestOneBit() method in Java 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.

