【问题标题】:Using a List(arraylist) in other methods(java)在其他方法(java)中使用列表(arraylist)
【发布时间】:2015-02-14 01:20:51
【问题描述】:

所以我有这个输入内容并将其放入数组列表的 java 代码:

public void adding() { 
    boolean loop = true;
    ArrayList<Game> thegame = new ArrayList<Game>();
    while(loop) {
        Scanner agame = new Scanner(System.in);
        System.out.print("name: \n");
        String Cgame = agame.nextLine();
        Scanner qty = new Scanner(System.in);
        System.out.print("the qty: \n");
        int CQty = qty.nextInt();


        Console wertgame = new Console(Cgame,Cqty);
        thegame.add(new Game(Cgame,Cqty));

        System.out.println("continue?");
        Scanner autre = new Scanner(System.in);
        int continu = other.nextInt();
        if(continu==1) {

        }
        else if(continu==2) {
            Main.menu();
        }
    }

    return thegame; 
}

但是,我想知道如何在其他方法中使用列表,我尝试了一些类似的方法

public void information(List<thegame>) {  
    System.out.print(thegame);  
})

我希望能够在其他方法中使用列表,并且能够显示和修改它。我是Java的初学者。

【问题讨论】:

    标签: java methods arraylist return


    【解决方案1】:

    您尚未将 thegame 声明为参数。改变

     public void information(List<thegame>) {  
            System.out.print(thegame);
    
        }}
    

    public void information(List<Game> thegame) {  
            System.out.print(thegame);
    
        }}
    

    【讨论】:

      猜你喜欢
      • 2018-03-27
      • 1970-01-01
      • 2012-12-03
      • 1970-01-01
      • 1970-01-01
      • 2016-05-09
      • 1970-01-01
      • 2023-02-17
      • 1970-01-01
      相关资源
      最近更新 更多