What is the better approach to convert primitive data type into String

后端 未结 9 733
独厮守ぢ
独厮守ぢ 2021-02-06 21:09

I can convert an integer into string using

String s = \"\" + 4; // correct, but poor style
or
String u = Integer.toString(4); // this is good

I

9条回答
  •  清歌不尽
    2021-02-06 21:40

    How about String.valueOf()? It's overridden overloaded for all primitive types and delegates to toString() for reference types.

提交回复
热议问题