I have a large String
in which I need to replace a few string pathern.
I have written code as below and I am getting very large memory usage in deployed environment.
I have read online to see if there is any more optimal way this can be re-written but could not find conclusive answer.
Can anyone give any suggestions for code below.
String response = "@very #large & string % STUFF";
System.out.println(response);
String[] SPECIAL_CHARACTERS = {"&","%","#","STUFF"};
for(int count = 0;count<SPECIAL_CHARACTERS.length;count++)
{
if(response.contains(SPECIAL_CHARACTERS[count]))
{
response = response.replace(SPECIAL_CHARACTERS[count],"");
}
}
System.out.println(response);