import java.io.File; import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.Scanner; public class Main { public static void main(String[] args) { ArrayList ppp = new ArrayList<>(); File f = new File("/home/gtowell/Public206/data/lab02/bigtrades.txt"); try (Scanner s = new Scanner(f)) { while (s.hasNextLine()) { String line = s.nextLine(); String[] aa = line.split(" "); Position pp = new Position(aa[0], Integer.parseInt(aa[1])); boolean updated=false; for (Position op : ppp) { if (op.getSymbol().equals(pp.getSymbol())) { op.updateAmount(pp.getAmount()); updated=true; break; } } if (!updated) { ppp.add(pp); } } s.close(); for (Position p : ppp) { if (p.getAmount()!=0) { System.out.print(p.getSymbol() + " " + p.getAmount() + "\n"); } } } catch (FileNotFoundException e) { System.err.println(e); } } }