转数组

char[] c=s.toCharArray();

很多时候需要将字符串转换为数组,之后进行遍历等操作。

//判断字符串是否为数字
public class cha {
    public static void main(String[] args) {
        String s="123a56";
        if(cha.IsNumber(s)) {
            System.out.println(s+" is number");
        }else {
            System.out.println(s+" is not number");
        }
    }
    public static boolean IsNumber(String str) {
        char[] c=str.toCharArray();//字符串转换为字符数组
        for(int i=0;i<c.length;i++) {
            if(Character.isDigit(c[i])) {
        }else {
            return false;
            }
        }
        return true;
    }
}
原文地址:https://www.cnblogs.com/xixixing/p/7593697.html