Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/343.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Java中向arraylist添加多个值_Java_Arraylist - Fatal编程技术网

如何在Java中向arraylist添加多个值

如何在Java中向arraylist添加多个值,java,arraylist,Java,Arraylist,我还是Java新手,我已经创建了许多ArrayList,我想从不同的方法调用它们。我已经多次使用while循环来运行代码。我想知道是否有人能帮我解决我的问题。 在代码停止运行之前,用户应该能够添加任意数量的比萨饼 public static void main(String[] args) { boolean test = true; while(test == true){ System.out.println("Please

我还是Java新手,我已经创建了许多ArrayList,我想从不同的方法调用它们。我已经多次使用while循环来运行代码。我想知道是否有人能帮我解决我的问题。 在代码停止运行之前,用户应该能够添加任意数量的比萨饼

public static void main(String[] args) {
           boolean test = true;
         while(test == true){    
          System.out.println("Please press 1 to start a new order, 2 to update an order or 3 to delete 0 to finish");
        Scanner inputValue = new Scanner(System.in);
          String value = inputValue.nextLine();
          int result = Integer.parseInt(value);
         Orders order = new Orders();
             int number = result;
             if (number == 1){
                order.add();
             }
             if (number == 2){
                 order.update();
             }
             if(number == 3){
                 order.delete();
             }
             if(number == 0){
                 order.calculatePizzas();
                test = false;
             }
         }


    }
order.add()

public ArrayList pizzaSizeA=new ArrayList();
public ArrayList sizePriceA=new ArrayList();
public ArrayList name=new ArrayList();
public ArrayList crapprice=new ArrayList();
public ArrayList base=new ArrayList();
public ArrayList sauceName=new ArrayList();
公共ArrayList炖锅=新ArrayList();
public ArrayList topping1=新的ArrayList();
public ArrayList t1Price=new ArrayList();
public ArrayList topping2=新的ArrayList();
public ArrayList t2Price=new ArrayList();
公共ArrayList数量=新建ArrayList();
//添加比萨饼,以便将其添加到阵列中。
System.out.println(“请输入基数?”);
扫描仪baseSize=新扫描仪(System.in);
字符串baseSize1=baseSize.nextLine();
JavaApplication4.Pizza Basesize1=新的JavaApplication4.Pizza();
Basesize1.大小(Basesize1);
pizzaSizeA.add(baseSize1);
//进入你想要的外壳
System.out.println(“\n请输入您的外壳?”);
Scanner crustty=新扫描仪(System.in);
String crustt=crustty.nextLine();
JavaApplication4.Pizza=新的JavaApplication4.Pizza();
JavaApplication4.比萨饼、面包皮;
加上(CRASTT);
//计算底价
JavaApplication4.Pizza basePrice=新的JavaApplication4.Pizza();
JavaApplication4.Pizza.base();
//酱价
System.out.println(“请输入酱油?”);
扫描器cSauce=新扫描器(System.in);
字符串cSauce1=cSauce.nextLine();
JavaApplication4.Pizza csauce=新的JavaApplication4.Pizza();
JavaApplication4.比萨酱(cSauce1);
sauceName.add(cSauce1);
//选择浇头
System.out.println(“选择要添加的配料?”);
扫描仪顶部=新扫描仪(System.in);
字符串toppin=top.nextLine();
JavaApplication4.Pizza to0ping=新的JavaApplication4.Pizza();
JavaApplication4.Pizza.topping1(toppin);
浇头1.添加(浇头);
//选择顶部2
System.out.println(“选择第二个浇头?”);
扫描仪top2=新扫描仪(System.in);
字符串toppin2=top2.nextLine();
JavaApplication4.Pizza to0pping2=新的JavaApplication4.Pizza();
JavaApplication4.Pizza.topping2(toppin2);
topping2.添加(topping2);
//数量
System.out.println(“请输入数量”);
扫描仪数量=新扫描仪(System.in);
字符串quan=qnatity.nextLine();
int q=整数。parseInt(quan);
订单。此。数量。添加(q);
系统输出打印项次(数量);
````````````````````````````````````````````````

我认为它适合您:

List<String> stooges = Arrays.asList("Larry", "Moe", "Curly");
下面是一些非常有用的代码示例的链接。好的例子有助于学习


祝你Java学习好运

请阅读这篇文章,了解他们为什么是个坏主意。你不需要12张名单。您需要一个
ArrayList
,其中
Pizza
是一个包含12个字段的类。您应该学习java中的类,并使用它们将Pizza的所有属性存储在单个对象中。这样,您只需要维护一个ArrayList。
List<String> stooges = Arrays.asList("Larry", "Moe", "Curly");
List<String> stooges = Arrays.asList("Larry", "Moe", "Curly");
myArray.add(stooges);
myArray.add(Arrays.asList("Larry", "Moe", "Curly"););