Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
Importance of the parseBoolean() method in Java?\\n
The parseBoolean() method is an important method of a Boolean class. The parseBoolean() is a static method and can parse the String method argument into a Boolean object. The parseBoolean() method of Boolean class returns the boolean represented by the string argument.
Syntax
public static boolean parseBoolean(String s)
Example
import java.util.Scanner;
public class ParseBooleanMethodTest {
public static void main(String[] args) {
System.out.print("Are you ready to play cricket(true/false)?");
Scanner scanner = new Scanner(System.in);
String str = scanner.nextLine();
scanner.close();
// Convert the user input into boolean
boolean answer = Boolean.parseBoolean(str);
if(answer) {
System.out.println("Yes, I am ready to play cricket");
} else {
System.out.println("No, I am not yet ready");
}
}
}
Output
Are you ready to play cricket(true/false)? true Yes, I am ready to play cricket
Advertisements
