Difference Between Boolean.TRUE and true in Java

Yatin B.Yatin B.
1 min read

Date: 2023-06-30

In Java, Boolean.TRUE and true both represent the boolean value true, but differ in type. Boolean.TRUE is an object of type Boolean (a wrapper class), suitable for use in collections or methods requiring objects. true is a primitive boolean literal, used in conditional statements and basic boolean operations. The choice depends on whether an object or primitive value is needed. Boolean.TRUE allows for method calls (e.g., .toString()), while true does not.

Read more: https://examples.javacodegeeks.com/difference-between-boolean-true-and-true-in-java

0
Subscribe to my newsletter

Read articles from Yatin B. directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Yatin B.
Yatin B.