We can convert String to boolean in java using Boolean.parseBoolean(string) method.
To convert String into Boolean object, we can use Boolean.valueOf(string) method which returns instance of Boolean class.
To get boolean true, string must contain "true". Here, case is ignored. So, "true" or "TRUE" will return boolean true. Any other string value except "true" returns boolean false.
Example:
Input: str="TRUE"
Output: true true
Approach
Java
public class StringToBoolean {public static void main(String[] args) {Boolean boolean1 = Boolean.valueOf("true");boolean boolean2 = Boolean.parseBoolean("true");System.out.println(boolean1);System.out.println(boolean2);}}
No comments:
Post a Comment