Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

read words from file into array

 
James Stanford
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to read in words from a file and then put those words into and array and sort the array, I kinda have a program but it isn't working can some one help me out with it, It would be nice to see some source code. I'm new to java and am having problems with the syntax and object orintation of the language. Anyways some help would be nice
 
Sam Moran
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you mean something like this:

I hope this helps!
 
James Stanford
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes thanks thats what I was looking for.
This is what I did to it but I'm getting compiler errors:

After I create I get to figure out how to put this info into a minimum hieght binary tree
I'll be having fun...hmmmm
[ March 01, 2003: Message edited by: James Stanford ]
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What are the errors and which lines do they refer to?
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So all you need is read a text file, split it in words, and end up with a sorted array of words?Or perhaps you are interested in the unique words in your document? In that case, a Set is more appropriate.If you do want unique words, but not a Set, tryAnd so forth. The combination of regular expressions and the Collections framework is good fun although still not as much as Perl.
- Peter
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I realised you may want to know the frequency of the words as well. The following code is a bit dirty, so don't show it to anyone as-is -- it will return a sorted list of words, each stating how many times it occurred in the source text:It doesn't return an array, it actually returns a Collection of Count objects. If you print them (which calls toString() on the objects) you'll get the promised list.HTH
- Peter
[ March 03, 2003: Message edited by: Peter den Haan ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic