Which of the below options has the best performance while converting string to Boolean?
boolean value = new Boolean("true").booleanValue();boolean value = Boolean.valueOf("true");boolean value = Boolean.parseBoolean("true");
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
is the worst. It creates new
Booleanobjects all the time. BTW,booleanValue()is not necessary; unboxing will do it for you.is much better. It uses a cached
Booleaninstance, but it performs unnecessary (although very cheap) unboxing.is best. Nothing is wasted, it operates barely on primitives, and no memory allocations are involved. BTW, all of them delegate to (Sun/Oracle):
If you are paranoid, you can create your own
toBoolean(String name)not ignoring case— it is negligibly faster: