Hey guys, Im having trouble adding an imported string file to a linked list (the purpose of the assignment is to find the most frequently used word) here's my code: (my problems in the mostFrequent class so you dont really have to look at the other classes. i just provided them so it can be easier for you to run with your compilers. Thank you.

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.*;

public class mostFrequent
{
    private int count;
    private String toWord;


    //LinkedList<Word> list = new LinkedList<Word>();
    public void Read()
    throws FileNotFoundException
    {
        Scanner input = new Scanner(System.in);
        input.close();
        FileReader reader = new FileReader("emma.txt");
        Scanner in = new Scanner(reader);
        in.useDelimiter("[^a-zA-Z]+");

        LinkedList<Word> list = new LinkedList<Word>();

        while (in.hasNext())
        {
            String s = in.next().toLowerCase();
            
            //System.out.println(s);
            Iterator<Word> itr = list.iterator();
            list.addAll(s);
           
            while(itr.hasNext())
            {
             Word w;
             w = itr.next();
             if(s == w.getWord())
             w.setCount();
            
             int highestCount = 0;
             String x;
             if(w.getCount() >= highestCount )
             highestCount = w.getCount();
             x = w.getWord();
            
            
            
            
            }


           //list.addLast(new Word(1,s));

            //System.out.println("The total amount of time is " +
            //System.currentTimeMillis()+ " milliseconds" );

          }


        }


    }
public class Word
{

    private String toWord;
    private int count;

    public Word(int c, String w)
    {
        toWord = w;
        count = c;
    }
    public String getWord()
    {
     return toWord;
    }
    public int setCount()
    {
     return count++;
    }
    public int getCount()
    {
     return count;
    }
  

}
import java.io.FileNotFoundException;

public class testmostFrequentWord
{
    public static void main(String[] args)
    throws FileNotFoundException
    {
        mostFrequent  m = new mostFrequent();
        //Word w = new Word();
        m.Read();
        //w.getWord();
        //w.getCount();
     

    }

}

when i use the list.addAll(s); command the error pops up and says "The method addAll(Collection<? extends Word>) in the type LinkedList<Word> is not applicable for the arguments (String)"
Think you guys can help?

It means what it says. addAll requires a parameter that is a Collection of Words, and you have passed a single String.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.