EXAMPLE 1 : Given a String "Maj1e4s57ti3c" You have to remove only digits from the given String to form a new String without any digit.
public class StrBuffr {
public static void main(String args[]){
String s = "Maj1e4s57ti3c";
char[] cs = s.toCharArray();
StringBuffer sb = new StringBuffer();
for (char c : cs) {
if(!Character.isDigit(c)){
sb = sb.append(c);
}
}
String finalStr = sb.toString();
System.out.println("After removing digits : "+ finalStr);
}
} OUTPUT :
After removing digits : Majestic
You may also like to know about :
No comments:
Post a Comment