• Post Reply Bookmark Topic Watch Topic
  • New Topic

Using Iterator with LinkedList  RSS feed

 
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.
 
Sheriff
Posts: 21204
87
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.
 
That which doesn't kill us makes us stronger. I think a piece of pie wouldn't kill me. Tiny ad:
ScroogeXHTML 7.1 - RTF to HTML5 / XHTML converter
https://coderanch.com/t/690611/ScroogeXHTML-RTF-HTML-XHTML-converter
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!