remove certain chars from string java code example
Example 1: how to remove all special characters from a string in java
String str= "This#string%contains^special*characters&.";
str = str.replaceAll("[^a-zA-Z0-9]", " ");
System.out.println(str);
Example 2: java string remove character
String str = "abcdDCBA123";
String strNew = str.replace("a", ""); // strNew is 'bcdDCBA123'