Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Java help. I need to print out frequency of words in a String using LinkedLists

  1. #1
    Junior Member
    Join Date
    Jan 2021
    Thanked 0 Times in 0 Posts

    Exclamation Java help. I need to print out frequency of words in a String using LinkedLists

    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.

    public static void main(String[] args)
    String test = "Informatics is the future It is a bridge to all things useful Informatics harnesses the power and possibility of digital technology to transform data and information into knowledge that people use every day This strong focus on the human use of computing helps people to interact with technology in the best and most efficient way possible Computer scientist believe informatics is the human part of the IT equation making computer software and hardware relatable accessible and enjoyable to use";
    String lower = test.toLowerCase();
    String[] split = lower.split(" ");
    LinkedList<String> words = new LinkedList<>(Arrays.asList(split));
    String strings = new String();
    LinkedList<Integer> count = new LinkedList<>();
    for(int j = 0; j<split.length; j++)
    for (int i = 0; i < test.length(); i++)
    if (words.contains(test))
    int index = words.indexOf(test);
    count.set(index, count.get(index) + 1);


    for (int i = 0; i < words.size(); i++)
    System.out.println(strings + " : " + count.get(i));


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Eastern Florida
    Thanked 2,635 Times in 2,585 Posts

    Default Re: Java help. I need to print out frequency of words in a String using LinkedLists

    I feel as though I am fairly close
    What does the program do now when it is compiled and executed? What needs to be added or changed?

    Please copy the console and paste it here that shows what happens .

    Also can you document how the program is trying to solve the problem? What are the steps the program is trying to take?

    Note: for initial testing use a much smaller input string. For example: "this is is test test test"

    Please edit your post and wrap your code with code tags:


    to get highlighting and preserve formatting.

    --- Update ---

    Also posted here: https://coderanch.com/t/738854/java/...dLists#3435874
    Please read: https://coderanch.com/wiki/660346/Wi...-Posting-Sites
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. How do I modify this code to display the frequency of words?
    By Mekii in forum Object Oriented Programming
    Replies: 1
    Last Post: January 7th, 2018, 01:27 AM
  2. Need to print the words
    By nimesh89 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: July 26th, 2013, 05:27 AM
  3. Replies: 2
    Last Post: September 29th, 2012, 07:42 PM
  4. Llist of words and frequency of each word
    By jkkj in forum Collections and Generics
    Replies: 7
    Last Post: August 16th, 2011, 09:59 AM
  5. Finding frequency and probability of characters in a string
    By Aberforth in forum What's Wrong With My Code?
    Replies: 4
    Last Post: October 31st, 2010, 02:02 AM