Convert integers to strings in java
If you have an integer, and want a string, concatenating it with "" is not as good as String.valueOf. It generates loads more code.
I realise that it's a bit more typing, but it is clearer what you want, and it is more efficient.
This also works for all the other unboxed types. long, boolean etc.
int i = 5;
String s1 = "" + i; // BAD
String s2 = String.valueOf(i); // GOOD
I realise that it's a bit more typing, but it is clearer what you want, and it is more efficient.
This also works for all the other unboxed types. long, boolean etc.
0 Comments:
Post a Comment
<< Home