gpt4 book ai didi

java - 如何给java足够的时间给变量赋值?

转载 作者:行者123 更新时间:2023-12-04 05:47:00 25 4
gpt4 key购买 nike

<分区>

我有一个循环,在循环结束时将 String[] 添加到 ArrayList(在类中声明,而不是方法)并且在循环的开头说 String[] 被清除了它的内容:

String[] a = new String[2];
while(true){
a[0] = "";
a[1] = "";
-----some code----

(that adds to a[0] and a[1])

-----some code----
//lets call our ArrayList list
list.add(a);
}

通常情况下,存储在列表中的是一个空的String。我认为这是因为 java 进入下一步太快了,但我不确定,请帮忙吗?这是我的所有代码:

static ArrayList<String[]> Names = new ArrayList<String[]>();
public static void read(BufferedReader stream){
String[] aux = new String[2];
char it = 2;

try{
while(it != (char) -1){
aux[0] = "";
aux[1] = "";
it = (char) stream.read();

while(Character.isLetter(it)){
aux[0] += it;
it = (char) stream.read();
}

it = (char) stream.read();

while(Character.isDigit(it)){
aux[1] += it;
it = (char) stream.read();
}
Names.add(aux);
stream.read();
}


}catch(IOException e){
System.out.print("IOException(read): ");
System.err.println(e.getMessage());
}

}

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com