Java阵列列表问题

Java阵列列表问题,java,arrays,variables,arraylist,reference,Java,Arrays,Variables,Arraylist,Reference,我试图允许一个“Admin”类创建多个数组。但是,每次运行此循环时,似乎都会删除先前创建的数组 do { System.out.println("\nWhat do you want " + "the name of your line to be?: "); String lineName= keyboard1.nextLine(); System.out.println("\n\

我试图允许一个“Admin”类创建多个数组。但是,每次运行此循环时,似乎都会删除先前创建的数组

   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));
do{
System.out.println(“\n您想要什么”
+“您的线路名称:”;
字符串lineName=keyboard1.nextLine();
System.out.println(“\n\n语法!\n”+“您的”+行名+
“队列已创建!\n”);
//创建一个包含“用户”信息的数组。
ArrayListqueue=新的ArrayList();
//创建一个数组数组,以允许“用户”查看所有可用的“行”。
ArrayListTotalines=新的ArrayList();
`//将数组名称添加到数组的数组中。
`总计行。添加(行名称);
//显示他们所有的行。
System.out.println(“这是您所有行的列表:\n”);
用于(字符串s:总计)
{
系统输出打印项次;
}
//询问管理员是否要创建另一行。
System.out.println(“\n是否要添加另一行?\n”
+“\n键入:是或否?”;
y=键盘1.nextLine();
}而(“Yes”。等于(y)|“Yes”。等于(y));
我在学校学习Java,我正在尽我最大的努力…仍然不熟悉Java中的许多工具,因为到目前为止我们只介绍了基础知识,但我非常确定我的问题是变量“lineName”是在先前创建的ArrayList实例上写入的。我知道什么了吗


您在每一轮上实例化一个新的
ArrayList
。您需要在循环之外执行此操作:

ArrayList<String>totalLines=new ArrayList<>();
do {
//...
arraylisttotalines=new ArrayList();
做{
//...

您在每一轮上实例化一个新的
ArrayList
。您需要在循环之外执行此操作:

ArrayList<String>totalLines=new ArrayList<>();
do {
//...
arraylisttotalines=new ArrayList();
做{
//...

是的,您已经掌握了一些东西。您的代码没有编译,您已经掌握了一些东西。您的代码没有编译