• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

read words from file into array

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What are the errors and which lines do they refer to?
 
author
Posts: 3252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 3252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic