
- Java Tutorial
- Java - Home
- Java - Overview
- Java - Environment Setup
- Java - Basic Syntax
- Java - Object & Classes
- Java - Constructors
- Java - Basic Datatypes
- Java - Variable Types
- Java - Modifier Types
- Java - Basic Operators
- Java - Loop Control
- Java - Decision Making
- Java - Numbers
- Java - Characters
- Java - Strings
- Java - Arrays
- Java - Date & Time
- Java - Regular Expressions
- Java - Methods
- Java - Files and I/O
- Java - Exceptions
- Java - Inner classes
- Java Object Oriented
- Java - Inheritance
- Java - Overriding
- Java - Polymorphism
- Java - Abstraction
- Java - Encapsulation
- Java - Interfaces
- Java - Packages
- Java Advanced
- Java - Data Structures
- Java - Collections
- Java - Generics
- Java - Serialization
- Java - Networking
- Java - Sending Email
- Java - Multithreading
- Java - Applet Basics
- Java - Documentation
- Java Useful Resources
- Java - Questions and Answers
- Java - Quick Guide
- Java - Useful Resources
- Java - Discussion
- Java - Examples
What is the importance of Boolean class in Java?n
The java.lang.Boolean class is a final class and it is a subclass of Object class. The Boolean class wraps the value of primitive datatype boolean into a Boolean object. An object of type Boolean contains a single field whose type is boolean. In other words, the wrapper classes create objects for primitive data types. This class provides many methods for converting a boolean to a String and a String to a boolean as well as other constants and methods useful when dealing with a boolean.
Syntax
public final class Boolean extends Object implements Serializable, Comparable
Example1
public class BooleanTest { public static void main(String[] args) { Boolean b; b = new Boolean(true); boolean b1; b1 = b.booleanValue(); String data = "The Primitive value of Boolean object " + b + " is " + b1; System.out.println(data); } }
Output
The Primitive value of Boolean object true is true
Example2
public class BooleanTest1 { public static void main(String args[]) { Boolean b1, b2; b1 = new Boolean(true); b2 = new Boolean("false"); System.out.println("b1 Value is : "+ b1.booleanValue()); System.out.println("b2 Value is : "+ b2.booleanValue()); System.out.println("b1 compareTo b2 : "+ b1.compareTo(b2)); System.out.println("b1 equals b2 : "+ b1.equals(b2)); } }
Output
b1 Value is : true b2 Value is : false b1 compareTo b2 : 1 b1 equals b2 : false
- Related Articles
- What is the importance of SwingUtilities class in Java?
- What is the importance of JViewport class in Java?
- What is the importance of JSeparator class in Java?
- What is the importance of Runtime class in Java?
- What is the importance of the GridBagConstraints class in Java?
- What is the importance of the CardLayout class in Java?
- What is the importance of the Container class in Java?
- What is the importance of a Cursor class in Java?
- What is the importance of a SwingWorker class in Java?\n
- What is the importance of the Throwable class and its methods in Java?
- Importance of a Locale class in Java?
- Importance of a Dictionary class in Java?
- Importance of MethodHandles class in Java 9?
- Importance of StringReader class in Java?\n
- What is the importance of "Java.lang.Class" in Java?

Advertisements