public class MySearchClass { private List mnTwins; private List allStars; public static void main(String[] args) throws Exception { MySearchClass searchClass = new MySearchClass(); searchClass.compareFiles(args); } private void compareFiles(String[] args) throws Exception { mnTwins = openAndReadFile(args[0]); allStars = openAndReadFile(args[1]); Collections.sort(mnTwins); Collections.sort(allStars); int twinsIndex = 0; int allStarIndex = 0; while(hasEntries(twinsIndex, allStarIndex)){ String twinsPlayer = mnTwins.get(twinsIndex); String allStarName = allStars.get(allStarIndex); if(nameMatch(twinsIndex, allStarIndex)){ System.out.println(twinsPlayer + "\t"+ allStarName); allStarIndex++; } else if(twinsPlayer.compareTo(allStarName) < 0) { twinsIndex++; } else { allStarIndex++; } } } private boolean nameMatch(int termedIndex, int activeIndex) { return allStars.get(activeIndex).startsWith(mnTwins.get(termedIndex)); } private boolean hasEntries(int twinsIndex, int allStarIndex) { return twinsIndex < mnTwins.size() && allStarIndex < allStars.size(); } private static List openAndReadFile(String fileName) throws Exception { FileReader fileReader = new FileReader(fileName); BufferedReader bufferedReader = new BufferedReader(fileReader); String line = bufferedReader.readLine(); List names = new ArrayList(); while(line != null){ names.add(line); line = bufferedReader.readLine(); } return names; } }