- class Demo
- {
- public static void main(String[] args)
- {
- String str = "a2sdf3ghj5kl";
- StringBuffer sbuf = new StringBuffer();
-
- char[] arr = str.toCharArray();
-
- for (int i = 0; i < arr.length; i++)
- {
- if(arr[i] >= '0' && arr[i] <= '9')
- {
- sbuf.append(arr[i]);
- }
- }
-
- System.out.println(sbuf.toString());
- }
- }
复制代码 |