This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Java in General and the fly likes read words from file into array Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "read words from file into array" Watch "read words from file into array" New topic
Author

read words from file into array

James Stanford
Greenhorn

Joined: Mar 01, 2003
Posts: 4
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


I knew I was a vim addict when I started editing my emacs with vim
Sam Moran
Ranch Hand

Joined: Sep 28, 2002
Posts: 86
Do you mean something like this:

I hope this helps!


We make a living by what we get, we make a life by what we give!
James Stanford
Greenhorn

Joined: Mar 01, 2003
Posts: 4
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

Joined: Dec 06, 2001
Posts: 3061
What are the errors and which lines do they refer to?


Java API Documentation
The Java Tutorial
Peter den Haan
author
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
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

Joined: Apr 20, 2000
Posts: 3252
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 ]
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: read words from file into array
 
Similar Threads
word compare
Exceeding String Array length
reading text file into GUI
updating array elements
NaturalLanguageMultiply- Hash map