Is there a difference in any ways (i.e performance, maintainability,...etc) between:
String str = String.valueOf(Boolean.TRUE);
vs
String str = "true";
Is there a difference in any ways (i.e performance, maintainability,...etc) between:
String str = String.valueOf(Boolean.TRUE);
vs
String str = "true";
is faster because it does not involve a function call ( except they may be optimized to the same)
I also consider it easier to read.
The
valueOfmethods are good for variables.Constant strings are better defined like this though:
That way they are constant and can be optimized for sure. So: