Parsing Text File and storing unique words

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • DCDeshpande
    New Member
    • Dec 2007
    • 1

    #1

    Parsing Text File and storing unique words

    Hi,

    I am new to Java and need to parse a simple txt file into unique tokens and store them in a data structure. Can someone please recommend the most efficient way to do this?

    I found out that StringTokenizer class can be used for parsing the text. I need to know the most efficient dynamic data structure available in Java to store the words and allow me to lookup words already in the list before adding new ones.

    Thanks,

    DCD
  • BigDaddyLH
    Recognized Expert Top Contributor
    • Dec 2007
    • 1216

    #2
    Most likely, your data structure is a Set or a Map. You'll need to describe it better.

    Here is Sun's tutorial on the Collections Framework:

    Colections

    Comment

    • BigDaddyLH
      Recognized Expert Top Contributor
      • Dec 2007
      • 1216

      #3
      Demo:
      [CODE=Java]import java.util.*;

      public class SetDemo {
      public static void main(String[] args) {
      String[] data = {"some", "sample", "data", "some", "more", "done"};
      Set<String> words = new TreeSet<String> (Arrays.asList( data));
      System.out.prin tln(words);
      //output: [data, done, more, sample, some]
      }
      }[/CODE]

      Comment

      Working...