title: Java - Calling private arraylist from class
body: <p>My template opens with a menu of options and the user inputs something between 1-3 to select one of the three options. </p>
  
  <p>When the user chooses option 1, it asks them to input a number <code>teamNumber</code>. One must instantiate the class <code>Team</code>, then it writes it to an arraylist.</p>
  
  <p>If there is at least one number in <code>numberList</code>, the user can select option 2. It asks them to input any of the numbers from the arraylist and searches it. If the number they input is found, then you input a String <code>teamMemberFirstName</code> and a char <code>firstInitialLastName</code>. Then it will write the input to a private arraylist located in another class <code>TeamMember</code>.</p>
  
  <p>Once they have input the info in option 1 and 2, they can choose option 3. It allows you to print the list of inputted names based on which team number you put them on.</p>
  
  <p>I am not sure how, in option 3, to call the private arraylist from the <code>TeamMember</code> class <code>teamList</code>. Any guidance on how to proceed with this step? My code is below.</p>
  
  <p>Main class:</p>
  
  <pre><code>public class Main {
      public static void main(String[] args) {
                          int choosing;
      Scanner scan = new Scanner(System.in);
  String input;
  int teamNumber;
  boolean stayInLoop;
  ArrayList&lt;Team&gt; numberList = new ArrayList&lt;Team&gt;();
  do {
  stayInLoop = true;
  System.out.println("1. Add a new team");
  System.out.println("2. Add a new team member");
  System.out.println("3. View teams");
  input = scan.nextLine();
  
  if (input.equals("1")) {
    System.out.println("Enter a team number:");
    teamNumber = scan.nextInt();
    scan.nextLine();
    Team addTeam = new Team(teamNumber);    
    numberList.add(addTeam);
  }
  
  if (input.equals("2")){
  boolean foundIt = false;
  boolean valid = true;
  System.out.println("Team number:");
  teamNumber = scan.nextInt();
  scan.nextLine();
    for (int a = 0; a &lt; numberList.size() &amp;&amp; foundIt == false; a++){
    Team addTeam = numberList.get(a);
      if (addTeam.findTeam() == teamNumber) {
      foundIt = true;
      System.out.println("Enter first name of team member:");
      String teamMemberFirstName = scan.nextLine();
      System.out.println("Enter first initial of last name:");
      char firstInitialLastName = scan.nextLine().charAt(0);
      TeamMember inputTeamMember = new TeamMember(teamMemberFirstName, firstInitialLastName);
      inputTeamMember.addMember(inputTeamMember, valid = true);
      System.out.println("Success!");
      }
    }
    if (foundIt == false) {
    System.out.println("Try again.");
    }
  }
  
  if (input.equals("3")){
    for (int a = 0; a &lt; numberList.size(); a++) {
    Team addTeam = numberList.get(a);
    //Not sure what to put where there are ????'s - I tried a few ideas and stuff I found online, but nothing worked    
    //I assume I call the method/class here????
    System.out.println("Team: " + addTeam.findTeam() + " Members: " + 
    "I will put the member called from the arraylist here????"); 
    }
  }
  }while (stayInLoop == true;)
  }}
  </code></pre>
  
  <p>TeamMember class:</p>
  
  <pre><code>public class TeamMember {
  
  private final String teamMemberFirstName;
  private final char firstInitialLastName;
  private ArrayList&lt;TeamMember&gt; teamList = new ArrayList&lt;&gt;();
  
  public TeamMember(String teamMemberFirstName, char firstInitialLastName) {
    this.teamMemberFirstName = teamMemberFirstName;
    this.firstInitialLastName = firstInitialLastName;
  }
  public int addMember(TeamMember member, boolean valid) {
    valid = teamList.add(member);
    return teamList.size();
  }
  }
  </code></pre>