Storing array of strings in specifies variables respectively

前端 未结 2 913
轮回少年
轮回少年 2021-01-24 15:10

I\'m a beginner at JAVA and I\'m writing this code that\'s supposed to receive an array of strings and store every string (array element) in the specified variables respectively

2条回答
  •  太阳男子
    2021-01-24 15:54

    There's a much easier way to do what you're trying to do, using String's split() method:

    static void func (){
        String[] split = sss.split(",");
        if (split.length < 5) {
            // this means some error in the input, need to handle
        }  
        male=split[0];
        blood=split[1];
        age=split[2];
        nat=split[3];
        dis=split[4];
    }
    

提交回复
热议问题