Double Value

What happens when you add a double value to a String?

Questions by yamxxx

Showing Answers 1 - 9 of 9 Answers

vijusatya

  • Jun 5th, 2009
 

It remains as string
For example:
String str="satya";
double d=10.45;
System.out.println("Value"+(str+d));- this will gives-satya10.45

  Was this answer useful?  Yes

Sarje

  • Aug 20th, 2009
 

When you add Double value to a String first the double value will be converted to String and appended to original String and new compelet String object will be created.
For exam:

String str = "Ram";
Double d = new Double(12.50d);
str = str + d;

now str is "Ram12.50"

  Was this answer useful?  Yes

Here consider String s="java"; Double d=new Double(1.4); Here when we write s="java" an object of type String is created and it is referenced to 's'.In the similar way when we write Double d=new Double(1.4); then double object is created and it is referenced to 'd'.if we write String s1=s+d; then new String object is created.first it takes "java" as string object and double object is converted to string object by using toString() method which is present in String class or it uses toString() method which is present in Object class.So now new String object is created as like this "java1.4"

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions