Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (7k points)

What is the correct way to declare a boolean variable in Java?

1 Answer

0 votes
by (13.1k points)
  • Use boolean instead of Boolean

  • Assign during declaration:

Boolean isMatch = email1.equals(email2);

  • Use final keyword if you can:

            final boolean isMatch = email1.equals(email2);

Last but not least:
if(isMatch==true)

Can be expressed as:

if(isMatch)

want to learn Java? Check out the Java certification from Intellipaat.

Browse Categories

...