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 StrBuildr {
public static void main(String args[]){
String
s = "Maj1e4s57ti3c";
char[] cs =
s.toCharArray();
StringBuilder
sb = new StringBuilder();
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