Created
September 20, 2012 13:57
-
-
Save tzafrir/3756082 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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