Jump to content
  • Advertisement
Sign in to follow this  
yves032784

[java] store each word into a treemap

This topic is 4831 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm storing a line of text into an ArrayList like so:

    private ArrayList linesOfText= new ArrayList();
    public ReadAndStore(String filename)  throws java.io.IOException 
    {
	
	FileReader fr = new FileReader(filename); 
	BufferedReader document = new BufferedReader(fr);


	for( String line = document.readLine(); line!=null; line = document.readLine() )
	    {
            System.out.println(line);
            StringTokenizer st = new StringTokenizer(line, "., \t\n\r\f");
		linesOfText.add( Collections.list(st) );

                

	    }



	document.close();
    }


basically, each word is stored into the ArrayList 'linesOfText' . Since I want to create a treemap, how could I store all the words with the line numbers in a treemap? Or, how could I get each word individually one by one? [Edited by - yves032784 on July 31, 2005 2:10:29 PM]

Share this post


Link to post
Share on other sites
Advertisement
If the line of text is separated by single spaces you could use this...


String line = document.readLine();
String words[] = line.split(" ");




Documentation for String might also be useful. It does have a lot of helpful methods for making Strings easier to work with.

Share this post


Link to post
Share on other sites
sorry, wasn't thinking.

so you're indexing the lines where each word appears?

as in word->all line #'s where you can find this word

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!