How to convert String into boolean in Java?

Views: 51   

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);
    
  2. Using Boolean.valueOf(String input) - This returns instance of Boolean type
    String input = "true";
    Boolean output = Boolean.valueOf(input);
    System.out.println(output);
    
On By