public void readFile() throws FileNotFoundException, IOException { this.myFile = new A(new B(new BufferedReader(new FileReader(new File(this.inFile))))); while(this.myFile.ready()){ String keyValue = this.myFile.readLine(); if(!keyValue.equals(" ") && !keyValue.isEmpty() && !keyValue.equals(" ")) if(tree.containsKey(keyValue)){ int value = tree.get(keyValue); tree.put(keyValue, ++value); }else tree.put(keyValue, 1); } TreeSet treeSet = new TreeSet(new MyComparator()); treeSet.addAll(tree.entrySet()); System.out.println(treeSet.toString()); }