- Java.util Package Classes
- Java.util - Home
- Java.util - ArrayDeque
- Java.util - ArrayList
- Java.util - Arrays
- Java.util - BitSet
- Java.util - Calendar
- Java.util - Collections
- Java.util - Currency
- Java.util - Date
- Java.util - Dictionary
- Java.util - EnumMap
- Java.util - EnumSet
- Java.util - Formatter
- Java.util - GregorianCalendar
- Java.util - HashMap
- Java.util - HashSet
- Java.util - Hashtable
- Java.util - IdentityHashMap
- Java.util - LinkedHashMap
- Java.util - LinkedHashSet
- Java.util - LinkedList
- Java.util - ListResourceBundle
- Java.util - Locale
- Java.util - Observable
- Java.util - PriorityQueue
- Java.util - Properties
- Java.util - PropertyPermission
- Java.util - PropertyResourceBundle
- Java.util - Random
- Java.util - ResourceBundle
- Java.util - ResourceBundle.Control
- Java.util - Scanner
- Java.util - ServiceLoader
- Java.util - SimpleTimeZone
- Java.util - Stack
- Java.util - StringTokenizer
- Java.util - Timer
- Java.util - TimerTask
- Java.util - TimeZone
- Java.util - TreeMap
- Java.util - TreeSet
- Java.util - UUID
- Java.util - Vector
- Java.util - WeakHashMap
- Java.util Package Extras
- Java.util - Interfaces
- Java.util - Exceptions
- Java.util - Enumerations
- Java.util Useful Resources
- Java.util - Useful Resources
- Java.util - Discussion
java Random nextBoolean() Method
Description
The java Random nextBoolean() method is used to get the next pseudorandom, uniformly distributed boolean value from this random number generator's sequence.
Declaration
Following is the declaration for java.util.Random.nextBoolean() method.
public boolean nextBoolean()
Parameters
NA
Return Value
The method call returns the next pseudorandom, uniformly distributed boolean value.
Exception
NA
Getting a Random Boolean Value Example
The following example shows the usage of Java Random nextBoolean() method. Firstly, we've created a Random object and then using nextBoolean() we retrieved a random boolean value and printed it.
package com.tutorialspoint; import java.util.Random; public class RandomDemo { public static void main( String args[] ) { // create random object Random randomNo = new Random(); // get next next boolean value boolean value = randomNo.nextBoolean(); // check the value System.out.println("Value is: " + value); } }
Output
Let us compile and run the above program, this will produce the following result.
Value is: true
Getting a Random Boolean Value Using a Given Seed Example
The following example shows the usage of Java Random nextBoolean() method. Firstly, we've created a Random object with a seed value and then using nextBoolean() we retrieved a random boolean and printed it.
package com.tutorialspoint; import java.util.Random; public class RandomDemo { public static void main( String args[] ) { // create random object Random randomNo = new Random(10); // get next next boolean value boolean value = randomNo.nextBoolean(); // check the value System.out.println("Value is: " + value); } }
Output
Let us compile and run the above program, this will produce the following result.
Value is: true
To Continue Learning Please Login
Login with Google