Friday, January 24, 2025
HomeProgrammingObject - Boolean vs Boolean in Java

Object – Boolean vs Boolean in Java

In Java, Boolean and boolean represent different types:

  1. boolean is a primitive data type that holds one of two values: true or false. It is used for simple flag or conditional logic and does not support methods or object behavior.
java
boolean isActive = true;
  1. Boolean is a wrapper class for the boolean primitive. It is part of the java.lang package and allows boolean values to be treated as objects. It can be used with collections and provides utility methods like Boolean.parseBoolean().
java
Boolean isActive = Boolean.TRUE;

Boolean is used when an object representation is needed, while boolean is for primitive operations.

RELATED ARTICLES
0 0 votes
Article Rating

Leave a Reply

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
- Advertisment -

Most Popular

Recent Comments

0
Would love your thoughts, please comment.x
()
x