remove a certain string from string java code example
Example 1: Java remove character from string
// Java remove character from string
public class RemoveOnlyLetters
{
public static void main(String[] args)
{
String strExample = "jd15352kLJJD55185716kdkLJJJ";
System.out.println("Before: " + strExample);
strExample = strExample.replaceAll("[a-zA-Z]", "");
System.out.println("After: " + strExample);
}
}
Example 2: java remove string from character
String str = "abcdDCBA123";
String strNew = str.replace("a", ""); // strNew is 'bcdDCBA123'