Tutorialspoint examples

Learn java tutorial with examples for beginners online

Convert boolean to string java program


Java convert boolean to string using String.valueOf() method

package com.tutorialspointexamples;
 
public class BooleanToString {
  public static void main(String args[]){
      boolean var = true;
      //convert boolean to string
      String str = String.valueOf(var);
      System.out.println("String is: "+str);
  }
}

Output:

String is: true

Download this example.

Java convert boolean to string using Boolean.toString() method

package com.tutorialspointexamples;
 
public class BooleanToString {
  public static void main(String args[]){
       boolean var = true;
      //convert boolean to string
      String str = Boolean.toString(var);
      System.out.println("String is: "+str);
  }
}

Output:

String is: true

Download this example.

Download tutorialspointexamples Android App
Copyright © 2018 Tutorialspoint examples DMCA.com Protection Status