0
"Admin"クラスで複数の配列を作成できるようにしようとしています。しかし、このループが実行されるたびに、作成された以前の配列が削除されるようです。Java ArrayListの問題
do {
System.out.println("\nWhat do you want "
+ "the name of your line to be?: ");
String lineName= keyboard1.nextLine();
System.out.println("\n\nCongratulations! \n"+ "Your "+ lineName +
" queue has been created! \n");
//Create an array that will hold "User" information.
ArrayList<User>queue=new ArrayList<>();
//Create an array of arrays to allow "User" to see all "lines" available to them.
ArrayList<String>totalLines=new ArrayList<>();
`//Add the array name to the array of arrays.
`totalLines.add(lineName);
//Show Admin all of their lines.
System.out.println("Here is a list of all of your lines: \n");
for (String s:totalLines)
{
System.out.println(s);
}
//Ask admin if they want to create another line.
System.out.println("\nDo you wish to add another line?\n"
+ "\nType:Yes or No?");
y = keyboard1.nextLine();
} while ("Yes".equals(y)||"yes".equals(y));
我々はこれまでに基礎をのみカバーしているが、私は私の問題というかなり確信しているとして、Javaで多くのツールに精通していない、まだ...私は学校でJavaを勉強し、私は自分のベストをしようとしています変数 "lineName"が、作成された前のArrayListインスタンスを上書きしているということです。私は何かにいるのですか?
はい、あなたは何かをしています。 –
あなたのコードはコンパイルされません – Daniel