Skip to content

Instantly share code, notes, and snippets.

@tzafrir
Created September 20, 2012 13:57
Show Gist options
  • Select an option

  • Save tzafrir/3756082 to your computer and use it in GitHub Desktop.

Select an option

Save tzafrir/3756082 to your computer and use it in GitHub Desktop.

Revisions

  1. tzafrir created this gist Sep 20, 2012.
    26 changes: 26 additions & 0 deletions gistfile1.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    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);
    }
    }
    }