File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP 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: 19723
    
  20

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
 
jQuery in Action, 2nd edition
 
subject: Using Iterator with LinkedList