> 
> **Possible Duplicate:**  
> 
> [Why can’t I Remove WhiteSpaces in Java?](https://stackoverflow.com/questions/14539791/why-cant-i-remove-whitespaces-in-java) 
> 
> 
> 

In a java program, to make some XML parseable without giving errors, I am substituting the `"&"` character with `"&amp;"` using the following code-- the variable 'origString' is storing each line in the input file (one by one)

```
 if(origString.contains("&"))
 {  

      System.out.println(" This line contains & --");

      System.out.println(" origstring=" + origString);

      origString.replace("&" , "&amp;");

      System.out.println(" origstring after replacing '&' =" + origString);
 }

```

However, when I run the above code, I am getting the same string value unchanged- i.e. the "&" remains as it is in the origString variable.

What am I doing wrong here? How do I correct this error?

Also, will the same problem apply to replacement of "<" , ">" , """, "'" characters (with equivalent text that is acceptable in XML files)?