Today, I accidentally tried to convert the string type to a Boolean type, looked up the API documentation, and found that the document seemed a bit out of place ...
Well, just send the test code, nonsense too lazy to say ...
String S1 = "false";
String s2 = "true";
String s3 = "FAlSe";
String S4 = "TrUe";
String S5 = "True_a";
The above string is separated by
Boolean.getboolean (S1);
Boolean.getboolean (S2)
Boolean.getboolean (S3);
Boolean.getboolean (S4);
Boolean.getboolean (S5);
All of the above 5 returned values are false
This is what the API documentation says:
Getboolean
public static Boolean Getboolean (String name)
Returns true if and only if the system attribute named with the parameter exists and is equal to the "true" string. (Starting with the 1.0.2 version of the JAVATM platform, the test for strings is no longer case-sensitive.) You can access system properties through the GetProperty method, which is defined by the system class.
Returns False if no property is named with the specified name or if the specified name is null or NULL.
But it turns out I don't know why.
Well, it turns out to be false, so what are we going to do, okay, there's another method called Boolean.parseboolean (string s);
Boolean.parseboolean (S1);
Boolean.parseboolean (S2)
Boolean.parseboolean (S3);
Boolean.parseboolean (S4);
Boolean.parseboolean (S5);
The API documentation is written like this:
public static Boolean Parseboolean (String s)
Resolves a string parameter to a boolean value. If the String argument is not null and equals "true" when the case is ignored, the returned Boolean represents a true value.
Example: Boolean.parseboolean ("true") returns TRUE.
Example: Boolean.parseboolean ("yes") returns false.
This time the conversion will be OK .... The results are: false, True, False, True, False
So, when you convert, just use parseboolean .
The above is the small series for everyone to bring the Java String type conversion Boolean type of method all the content, I hope that we support cloud Habitat Community ~