This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Using Iterator with LinkedList Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Using Iterator with LinkedList" Watch "Using Iterator with LinkedList" New topic
Author

Using Iterator with LinkedList

Dave DiRito
Ranch Hand

Joined: Feb 08, 2008
Posts: 77
I'm trying to use an iterator in a method to count the number of duplicates in a list of integers. I have a logic problem in it somewhere because it only counts one set of duplicates every time even if there's more than one. Here's the code:

Thanks,
Dave
Dave DiRito
Ranch Hand

Joined: Feb 08, 2008
Posts: 77
Just figured it out:
Dave DiRito
Ranch Hand

Joined: Feb 08, 2008
Posts: 77
Also, the list must be sorted for this method to work. I used Collections.sort(list); before passing the list to the method.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19656
    
  18

You'd better not use == comparison even for Integers. Use equals() instead, and beware of null values.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Using Iterator with LinkedList
 
Similar Threads
Eliminating Duplicate in Arraylist and moving the dups to another arraylist.
ArrayList with Iterator
What is an assignment?
removing dups using Set
Removing dups from array