• Advertisement
Sign in to follow this  

[java] store each word into a treemap

This topic is 4587 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
mako, I want to be able to extract each word from ArrayList linesOfText in a new method instead.

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