Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Using Iterator with LinkedList

 
Dave DiRito
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just figured it out:
 
Dave DiRito
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20667
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You'd better not use == comparison even for Integers. Use equals() instead, and beware of null values.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic