Speichern eines Arrays von Strings in spezifiziert Variablen bzw.

Ich bin ein Anfänger bei JAVA und schreibe diesen Code, der ein Array von Strings empfangen und jeden String (Array-Element) in den angegebenen Variablen speichern soll. Es wird jedoch nur das erste Element gespeichert. Unten ist der Code:

package ontoretrive;

import org.apache.commons.lang3.ArrayUtils;

public class j {
static String sss= "male,O+,45,saudi,brain_diseases";
static int size =sss.length();

static String male="";
static String blood="";
static String age="";
static String nat="";
static String dis="";
static char temp;
static void func (){
    char[] charArray = sss.toCharArray();
    Character[] charObjectArray = ArrayUtils.toObject(charArray);
    int count=0;
    int x=0;
    while (x< size){
        temp =charObjectArray[x];
while(temp!=','&&count==0){
                male=male+temp;
                x++;
                temp =charObjectArray[x];}
x++;
temp =charObjectArray[x];

count++;            

while(temp!=','&&count==1){
        blood=blood+temp;
        x++;
        temp =charObjectArray[x];}
x++;
temp =charObjectArray[x];
count++;            

while(temp!=','&&count==2){
        age=age+temp;
        x++;
        temp =charObjectArray[x];
}x++;
temp =charObjectArray[x];
count++;            

while(temp!=','&&count==3){
        nat=nat+temp;
        x++;
        temp =charObjectArray[x];
}x++;
temp =charObjectArray[x];
count++;            


while(temp!=','&&count==4){
        dis=dis+temp;
        x++;
        //temp =charObjectArray[x];
        }
x++;
// temp =charObjectArray[x];
count++;    }

System.out.println(male);//end while1
System.out.println(blood);//end while1
System.out.println(age);//end while1
System.out.println(nat);//end while1
System.out.println(dis);//end while1

}//end func
public static void main(String[] args) {
    System.out.println("dis1");
    func();
   System.out.println(male);//end while1

    //System.out.println("dis3");


}
}    //end class

Antworten auf die Frage(4)

Ihre Antwort auf die Frage