• 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
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

counting specific words from a text file

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi can any one help me, i need to count specific words which are kept in a array list and then i need to count how many times theses words appear in a text file.
so far i can count specific characters from a array list and see how many times they appear in a text file. i am also able to count the number of lines, characters and even how many words appear in a text file.

below is the code i have done so far andy help would be welcomed.

thank you for your time.

[ December 06, 2004: Message edited by: sukh singh ]

[ Jess added UBB [code] tags to perserve whitespace ]

[ December 06, 2004: Message edited by: Jessica Sant ]
 
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Sukh,

I replied to your question in the intermediate forum as well. SO, Here it goes. IF you want to read a line and then compare that with some word. You should StringTokenizer method, it breaks down the line word by word. Onto your problem. Lets say the words that you want to count are : for, else, is, are. There are 2 ways to do it. You don't have to store them in any array. For example:



let me know if this way works for you . Take care.

Mala
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If the magic words are in an ArrayList you can expand on the example above a bit. Get a word, see if it's in the ArrayList, maybe find out where in the ArrayList and increment a counter in a regular int[] array. "See if it's in the ArrayList" is a hint to go read the JavaDoc. Have fun!
 
when your children are suffering from your punishment, tell your them it will help them write good poetry when they are older. Like this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic