CodesJava

Easy learning with example program codes

Boolean to string in java


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

package com.codesjava;
 
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.codesjava;
 
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.

Please follow and like us:
Posted in Java   


Copyright © 2019 CodesJava DMCA.com Protection Status SiteMap Reference: Java Wiki