Best approach to converting Boolean object to string in java

后端 未结 7 864
暖寄归人
暖寄归人 2020-12-13 01:51

I am trying to convert boolean to string type...

Boolean b = true;
String str = String.valueOf(b);

or

Boolean b = true;
Str         


        
7条回答
  •  無奈伤痛
    2020-12-13 02:14

    If you're looking for a quick way to do this, for example debugging, you can simply concatenate an empty string on to the boolean:

    System.out.println(b+"");
    

    However, I strongly recommend using another method for production usage. This is a simple quick solution which is useful for debugging.

提交回复
热议问题