Using a list (arraylist) in other methods (java)

so I have this java code that injects stuff and puts it in a list of arrays:

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; 
}

      

However, I'm wondering how to use the list in other methods, I've tried some things like

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

      

I want to be able to use the list in other methods and be able to display it as well as modify it. I am new to Java.

+3


source to share


1 answer


You have not specified thegame

as a parameter. Change

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

    }}

      



to

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

    }}

      

+6


source







All Articles