[java] store each word into a treemap

Started by
2 comments, last by mako_5 18 years, 8 months ago
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]
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.
mako, I want to be able to extract each word from ArrayList linesOfText in a new method instead.
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

This topic is closed to new replies.

Advertisement