How can i concatenate Double to String in java?
I have following piece of code:
Double price = 5.34;
String trade = MSFT;
now I have String key = price + trade, not sure if this is right way of doing it, any suggestions?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Java string concatenation is done by default with the
+sign.But there are times when this is not a good practice since this will create a new string instance every time you do it, so if you are in a loop this will create a new string in memory for each iteration.
So for simple cases, the
+is perfectly valid.For other cases, you should use StringBuilder.