I have a string in my Java program which is read from database.
This may contain special characters in between as below:
You can use String#replaceAll:
myStr = myStr.replaceAll("[^a-zA-Z0-9]+", "")
The ^ is saying: "Keep all chars that are not in the specified ranges inside the square brackets".
^