在其他方法(java)中使用List(arraylist)



所以我有这个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的初学者。

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

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

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

最新更新