I am trying to convert boolean to string type...
Boolean b = true;
String str = String.valueOf(b);
or
Boolean b = true;
Str
Depends on what you mean by "efficient". Performance-wise both versions are the same as its the same bytecode.
$ ./javap.exe -c java.lang.String | grep -A 10 "valueOf(boolean)"
public static java.lang.String valueOf(boolean);
Code:
0: iload_0
1: ifeq 9
4: ldc #14 // String true
6: goto 11
9: ldc #10 // String false
11: areturn
$ ./javap.exe -c java.lang.Boolean | grep -A 10 "toString(boolean)"
public static java.lang.String toString(boolean);
Code:
0: iload_0
1: ifeq 9
4: ldc #3 // String true
6: goto 11
9: ldc #2 // String false
11: areturn