I would like to convert my boolean object to String. Which among the following would be the better /right way of doing it and why?
boolean booleanValue = true;
String strValue = Boolean.toString(booleanValue);
or
boolean booleanValue = true;
String strValue = booleanValue + "";
EDIT
The below answers prompts me to add few more
boolean booleanValue = true;
String strValue = String.valueOf(booleanValue);
and for non-primitive data types like Integer
Integer i = 10;
String strValue = i.toString();
So, finally we have three different types Boolean.toString()
, concat with +
, String.valueOf()
to convert any data type to String