Convert string to boolean

ReturnMethodSummary
static booleanparseBoolean(String s)Parses the string argument as a boolean.
static BooleanvalueOf(boolean b)Returns a Boolean instance representing the specified boolean value.
static BooleanvalueOf(String s)Returns a Boolean with a value represented by the specified string.

public class Main {
 
    public static void main(String[] args) {
     System.out.println(Boolean.parseBoolean("true"));
     System.out.println(Boolean.valueOf("true"));
    }
}

The output:


true
true
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.