please help java linked lists

[b]I am trying to: [/b]
[color=Blue]1)read a word from a txt file
2)search for the word in my linked list (at beginning it will be empty)
3)if the word is found then increment count for that word
4)if the word is not found insert it into the list [/color]

The goal is to output all words from the txt file and sort them depending on how many times a word appears. So far I can read the txt file into a linkedlist called ll and then print it out again. I would really appreciate some advice on how to set up my loops to get where I need to go with this.

Thanks in advance!

[code]public static void getTxt(){
//read from txt
BufferedReader in=new BufferedReader(new FileReader("biblewords.txt"));
String words;
LinkedList ll=new LinkedList();
long start, stop;
//read whole file line by line and stick it in ll
while((words=in.readLine()) !=null){
}//end while
in.close();//closes buffer reader
String first=ll.getFirst();
String last=ll.getLast();
System.out.println(ll.indexOf(first) +": "+ first);
System.out.println(ll.indexOf(last) +": "+ last);
System.out.println("Time elapsed: "+((stop-start)/1000.0)+" seconds");//times how long it takes to complete this section of code
}catch (Exception e){
System.err.println("This program has encountered an error: " + e.getMessage());
}//end try catch
}//end getTxt[/code]


  • It forgot to mention that I am doing all of this in that while loop. I will need an if/else statment to check if it is in the linked list and then somehow increment a counter for that word if it allready lives there. That is what I need help with : )

    Thanks again
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


In this Discussion