Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (3.4k points)
How to convert String object to Boolean object?

1 Answer

0 votes
by (46k points)

Try (depending on what effect example you require):

Boolean boolean1 = Boolean.valueOf("true");

boolean boolean2 = Boolean.parseBoolean("true");

Advantage:

  • Boolean: this doesn't create new examples of Boolean, so execution is better (and less garbage-collection). It reuses the two examples of either Boolean.TRUE or Boolean.FALSE.

  • boolean: no situation is needed, you apply the fundamental type.

The suitable documentation is in the Javadoc.

Autoboxing could also be done, but it has a fulfillment cost.

I imply to apply it only when you would cast yourself, not at the cast is avoidable

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Aug 6, 2019 in Java by Anvi (10.2k points)
0 votes
1 answer
0 votes
1 answer

Browse Categories

...