470,643 Members | 1,566 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,643 developers. It's quick & easy.

Parsing Text File and storing unique words


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.


Dec 27 '07 #1
2 2562
1,216 Expert 1GB
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:

Dec 27 '07 #2
1,216 Expert 1GB
Expand|Select|Wrap|Line Numbers
  1. import java.util.*;
  3. public class SetDemo {
  4.     public static void main(String[] args) {
  5.         String[] data = {"some", "sample", "data", "some", "more", "done"};
  6.         Set<String> words = new TreeSet<String>(Arrays.asList(data));
  7.         System.out.println(words);
  8.         //output: [data, done, more, sample, some]
  9.     }
  10. }
Dec 27 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 posts views Thread by Noam Dekers | last post: by
13 posts views Thread by Nickolay Kolev | last post: by
1 post views Thread by daldridge | last post: by
13 posts views Thread by Chris Carlen | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.