String operations

Posted by NEO on Stack Overflow See other posts from Stack Overflow or by NEO
Published on 2011-01-10T01:09:38Z Indexed on 2011/01/10 2:53 UTC
Read the original article Hit count: 293

Filed under:
|
|
|

I am trying to find the most repeated word in a string. My code is as follows:

public class Word 
{

    private String toWord;
    private int Count;

    public Word(int count, String word){
        toWord = word;
        Count = count;
    }
    public static void main(String args[]){
        String str="my name is neo and my other name is also neo because I am neo";
        String []str1=str.split(" ");
        Word w1=new Word(0,str1[0]);
        LinkedList<Word> list = new LinkedList<Word>();
        list.add(w1);
        ListIterator itr = list.listIterator();
        for(int i=1;i<str1.length;i++){
            while(itr.hasNext()){
                if(str1[i].equalsTO(????));
                else
                    list.add(new Word(0,str1[i]));
            }

How do I compare the string from string array str1 to the string stored in the linked list and then how do i increase the respective count.

I will then print the string with the highest count, I dont know how to do that either.

© Stack Overflow or respective owner

Related posts about java

Related posts about algorithm