본문 바로가기
Developer/Java

[Java] boolean to String

by 순수한소년 2018. 6. 18.
728x90
반응형

출처

https://beginnersbook.com/2015/05/java-boolean-to-string/


boolean boovar = true;
String str = String.valueOf(boovar);
boolean boovar = false;
String str = Boolean.toString(boovar);


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
package com.beginnersbook.string;
 
public class BooleanToString {
    public static void main(String[] args) {
        
        /* Method 1: using valueOf() method
         * of String class.
         */
        boolean boovar = true;
        String str = String.valueOf(boovar);
        System.out.println("String is: "+str);
        
        /* Method 2: using toString() method 
         * of Boolean class
         */
        boolean boovar2 = false;
        String str2 = Boolean.toString(boovar2);
        System.out.println("String2 is: "+str2);
    }
}
cs


728x90
반응형