logo image

How to convert String into boolean in Java?



There are two ways you can convert a String into boolean in Java

  1. Using Boolean.parseBoolean(String input) - This returns primitive boolean
String input = "true";
boolean output = Boolean.parseBoolean(input);
System.out.println(output);
  1. Using Boolean.valueOf(String input) - This returns instance of Boolean type
String input = "true";
Boolean output = Boolean.valueOf(input);
System.out.println(output);