Hints for java.lang.String.replace problem?
java, replace, string
Solution
You need to assign the new value back to the variable.
double myDouble = myObject.getDoubleMethod(); // returns 38.1882352941176
System.out.println(myDouble);
String myDoubleString = "" + myDouble;
System.out.println(myDoubleString);
myDoubleString = myDoubleString.replace(".", ",");
System.out.println(myDoubleString);
myDoubleString = myDoubleString.replace('.', ',');
System.out.println(myDoubleString);
Problem
I would like to replace "." by "," in a String/double that I want to write to a file. Using the following Java code ``` double myDouble = myObject.getDoubleMethod(); // returns 38.1882352941176 System.out.println(myDouble); String myDoubleString = "" + myDouble; System.out.println(myDoubleString); myDoubleString.replace(".", ","); System.out.println(myDoubleString); myDoubleString.replace('.', ','); System.out.println(myDoubleString); ``` I get the following output ``` 38.1882352941176 38.1882352941176 38.1882352941176 38.1882352941176 ``` Why isn't replace doing what it is supposed to do? I expect the last two lines to contain a ",". Do I have to do/use something else? Suggestions?