Skip to content

Instantly share code, notes, and snippets.

@tzafrir
Created September 20, 2012 13:57
Show Gist options
  • Save tzafrir/3756082 to your computer and use it in GitHub Desktop.
Save tzafrir/3756082 to your computer and use it in GitHub Desktop.
void readLinesNoDups(String filename) {
File f = FileReader(filename);
Set lines = new HashSet<String>();
List resultLines = new ArrayList<String>();
for (String line : f.lines()) {
if (!lines.contains(line)) {
lines.add(line);
resultLines.add(line);
}
}
for (String line : resultLines) {
System.out.println(line);
}
}
void readHugeFile(String hugeFilename) {
File f = FileReader(filename);
Set<Integer> hashedSet = new HashSet<Integer>();
for (String line : f.lines()) {
if (!hashedSet.contains(line.hashCode())) {
hashedSet.insert(line.hashCode());
System.out.println(line);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment