我有一个循环,在循环结束时a 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);
}
Run Code Online (Sandbox Code Playgroud)
因此,列表中存储的内容通常是空的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 = …Run Code Online (Sandbox Code Playgroud)