0 votes
1 view
in Java by (3.4k points)
How to convert String object to Boolean object?

1 Answer

0 votes
by (46.1k 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
Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...