| 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: 19232
|
|
|
You'd better not use == comparison even for Integers. Use equals() instead, and beware of null values.
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
 |
|
|
subject: Using Iterator with LinkedList
|
|
|