我正在尝试打印此ArrayList对象,但是我遇到的问题是它提供的输出不同于我为团队设置的值。我创建了一些团队示例来显示程序的输出。
package com.company.RugbyTable;
import java.util.ArrayList;
public class TeamList {
private ArrayList <Team> teams;
public TeamList() {
this.teams = new ArrayList <Team> ();
}
public TeamList(ArrayList <Team> teams) {
this.teams = teams;
}
public void addTeam (Team newTeam) {
this.teams.add (newTeam);
}
public String toString () {
String s = "";
s = "Current Members\n\n";
for (Team c: this.teams) {
s += c.toString ();
s += "\n";
}
return s;
}
//add method to remove teams
//add method to update teams
public static void main(String[] args) {
TeamList currentTeams= new TeamList();
Team leeds = new Team("Leeds Rhinos");
Team sheffield = new Team("Sheffield");
Team doncaster = new Team ("Doncaster");
Team southamptom = new Team ("Southampton");
Team london = new Team ("London");
Team burnley = new Team("Burnley");
currentTeams.addTeam(leeds);
currentTeams.addTeam(sheffield);
currentTeams.addTeam(doncaster);
currentTeams.addTeam(southamptom);
currentTeams.addTeam(london);
currentTeams.addTeam(burnley);
System.out.println(currentTeams);
}
}
这是输出; 现有成员
com.company.RugbyTable.Team@1540e19d
com.company.RugbyTable.Team@677327b6
com.company.RugbyTable.Team@14ae5a5
com.company.RugbyTable.Team@7f31245a
com.company.RugbyTable.Team@6d6f6e28
com.company.RugbyTable.Team@135fbaa4
Process finished with exit code 0