
Removing characters from a string

Example:
public class CharReplace{
public static void main(String []args){
String str="Hello 123.you are At 3456";
String result=str.replaceAll("[a-z,A-Z]","");
System.out.println(result.trim());
}
}
Description: str.replaceAll(?type1?,?type2?) method replaces all type1 into type2.Here our goal to remove all char. so you can replace all character into ?? by using replaceAll() method. trim() method removes all blank spaces in the string.