Boolean values in JavaLast Updated : 17 Mar 2025 In programming, we generally need to implement values that can only have one of two values, either true or false. For this purpose, Java provides a special data type, i.e., boolean, which can take the values true or false. The boolean values can be declared with the boolean keyword. Consider the following example. Output: true you are logged into the system For general purpose, we often use boolean expressions that return boolean value either true or false. For example, the comparison operator returns boolean values. Output: false Boolean Class in JavaIn Java, the package java.lang provides the definition for a wrapper class Boolean that wraps the primitive type boolean in the object. The class also provides useful general-purpose methods that can be used to convert boolean values to string or vice-versa. This class provides two constructors to create the objects, which are given below. The above constructor accepts a primitive boolean value and creates an object which contains a single boolean value. The above constructor creates a boolean object which contains a value "true" if the string argument is not null and is equal (ignore case) to the string "true". Otherwise, a boolean value false will be created. Boolean class provides the following methods.
|
We request you to subscribe our newsletter for upcoming updates.

We deliver comprehensive tutorials, interview question-answers, MCQs, study materials on leading programming languages and web technologies like Data Science, MEAN/MERN full stack development, Python, Java, C++, C, HTML, React, Angular, PHP and much more to support your learning and career growth.
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India