java replace char with empty 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 swap two characters
String originalString = "abcde";
//Strings are immutable
char[] c = originalString.toCharArray();
//Swap
char temp = c[0];
c[0] = c[1];
c[1] = temp;
//Result
String swappedString = new String(c);