This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan 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 EJB 3 in Action this week in the EJB and other Java EE Technologies 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: 19538
    
  16

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
removing dups using Set
ArrayList with Iterator
What is an assignment?
Eliminating Duplicate in Arraylist and moving the dups to another arraylist.
Removing dups from array