转数组

Posted 夕西行

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了转数组相关的知识,希望对你有一定的参考价值。

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;
    }
}

 

以上是关于转数组的主要内容,如果未能解决你的问题,请参考以下文章