i have some code which reads from a .txt file and picks up PL football teams from the file... and sends them to a String... how can i make it so i get only one team once i.e no teams repeat?
this is my code:
import java.util.ArrayList; import java.util.Arrays; import java.util.Comparator; import java.util.List; import java.io.FileReader; import java.io.BufferedReader; import java.io.IOException; public class generatortest { private static class Team{ private String team; int GamesPlayed; int GoalDifference; int GamesWon; int GamesDrawn; int GamesLost; int Points; public void setteam(String team) //defining team names as string { this.team = team; //Sets team } public String toString() { StringBuilder organiselayout = new StringBuilder(); organiselayout.append(this.team); return organiselayout.toString(); } } generatortest() throws IOException { BufferedReader bufferedReader = new BufferedReader(new FileReader("PL.txt")); //Reads In Assignment file or your file. if (bufferedReader != null) { String text; //sets each line read as a text string while ((text = bufferedReader.readLine()) != null) { String[] split = text.split(":"); // splits the string text at each colon List<Team> Games = new ArrayList<Team>(); //Listing the array of the Team class // If the Length of string is greater than 4 then match is classed as valid if (split.length >= 4) { Team League = new Team(); //adds the text values to the Team Class League.setteam(split[0].trim()); //the 0 string is the home team when reading from the file League.setteam(split[1].trim()); //the 1 string is the away team when reading from the file Games.add(League); //adds the previous games into 1 entity System.out.println(League.toString()); } } bufferedReader.close(); //closes reader } } public final static void main(String [] args) throws IOException { new generatortest(); } }
I know it contains integers that aren't used locally at the minute but i eventually want to compare this list and re-loop through the text file taking more information to build myself a league table..
Thanks RSYR