java - What is the better approach to convert primitive data type into String -
java - What is the better approach to convert primitive data type into String -
i can convert integer string using
string s = "" + 4; // correct, poor style or string u = integer.tostring(4); // i can convert double string using
string s = "" + 4.5; // correct, poor style or string u = double.tostring(4.5); // i can utilize string s = "" + dataapproach convert either int or double string. while if wants utilize other approach using tostring() have utilize wrapper class of each info type. why in some books mentioned first approach poor 1 while sec 1 better. which 1 improve approach , why?
i use
string.valueof(...) you can utilize same code types, without hideous , pointless string concatenation.
note says want - string value corresponding given primitive value. compare "" + x approach, you're applying string concatenation though have no intention of concatenating anything, , empty string irrelevant you. (it's more expensive, it's readability nail mind more performance.)
java
Comments
Post a Comment