• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Ron McLeod
  • Tim Cooke
Sheriffs:
  • Devaka Cooray
  • paul wheaton
  • Mark Herschberg
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Frits Walraven
  • Jj Roberts
Bartenders:
  • Carey Brown
  • salvin francis
  • Piet Souris

Counting frequency of words using LinkedLists

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello, I am new here and I am learning to code. I am doing an exercise in which I need to find the frequency of words in a given string and put them in a LinkedList. I feel as though I am fairly close but no cigar. Any help would be appreciated.

 
Bartender
Posts: 7789
70
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you ever used Maps? Counting the frequency of something is also known as computing a histogram. This is usually done with a Map.
Where the key is the word and the value is an integer which is a count of the number of times the word appears. You have to iterate through all your words, and for each word, if it is not in the Map then add it with a count of one, if it is in the Map increment the count.
 
Marshal
Posts: 72059
312
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch

Why do you have to use a linked list? To continue from what Carey said: there is an example of counting using the old technique (not a Stream) in the Java™ Tutorials.
 
Campbell Ritchie
Marshal
Posts: 72059
312
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for noticing, Norm
 
Norm Radder
Master Rancher
Posts: 4188
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It keeps me from spending any more time with this OP on the other forum.  Once a question is posted here the locals will take care of doing the design and debugging for the OP and help him get a working program without him having to  spend too much time working through details.
 
Marshal
Posts: 26381
81
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Eric Dolland wrote:Hello, I am new here and I am learning to code. I am doing an exercise in which I need to find the frequency of words in a given string and put them in a LinkedList.



Hi Eric, welcome to the Ranch!

One thing about programming, if you try to write code and you don't have a clear description of what the code is supposed to do, then you're going to flounder. That's not just beginners, that's everyone.

So: what is your code supposed to do? I can see that you're supposed to extract words from a string. Then you're supposed to find the frequency of those words; I'm going to assume that's the frequency of the words in that set of words. And then I'm stuck. You're supposed to put "them" in a LinkedList. What's "them"? The words, or the frequencies?

Hopefully you're working from an assignment which states the requirements more clearly. Could you tell us what the requirements are, then?
 
Willie Smits can speak 40 languages. This tiny ad can speak only one:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic