ArrayLists inside of a HashMap.

Discussion in 'Plugin Development' started by Irantwomiles, Aug 11, 2015.

Thread Status:
Not open for further replies.
  1. Offline

    javipepe

    The thing is that the createteam method should be in another class maybe "TeamUtils", then to get the team you created you could just do something like this:

    Code:
    TeamBuilder.createTeam(color, name, max);
    Team created = TeamBuilder.getTeamByName(name);
     
  2. Offline

    Irantwomiles

    Creating the team works but getting the team by name and/or getting the people in it is what I'm having trouble with. Don't I need a list where I have my cmd's for my Teams?
     
  3. Offline

    javipepe

    What you need is a list of all your teams, which you already have in the TeamUtils class, an ArrayList<Team> called teams. Then in the same class there is the getTeamByName() method which should work:

    Code:
    public static Team getTeamByName(String s){
        
                Team target = null;
                for(Team t : teams){
                    if(t.getName().equalsIgnoreCase(s)){
                        target = t;
                    }
                }
                return target;
            }
        }
    I can't see where is the trouble? Please explain your error or what's happening to make you unable to iterate through all of the teams and returning the one that has the name desired.
     
  4. Offline

    Evaluations


    1. Code:
          public static Team getTeamByName(String s) {
              for (Team t : teams) {
                  if (t.getName().equalsIgnoreCase(s)) {
                      return t;
                  }
              }
              return null;
          }
      
      
    Why not do it like that?
     
    Last edited: Aug 13, 2015
  5. Offline

    Konato_K

    @Evaluations If you're going to call this method several times then probably using a Map<String, Team> would be better.
     
    teej107 likes this.
Thread Status:
Not open for further replies.

Share This Page