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

how to get duplicates?

 
catherine matthews
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
here is my algorithm to find duplicates . the arrays statement and statement2 has the same elemnts.... I compare them if it occurs more then once i need to indicate....



I do not know where i went wrong.... please help... i dont get any output for the set of input like this....
import javax.swing.*;
import java.util.regex.*;
import java.util.*
import java.awt.event.*;;
import java.util.regex.*;
 
Keith Lynn
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look carefully at what sk and s1 indicate.
[ July 15, 2006: Message edited by: Keith Lynn ]
 
catherine matthews
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
bingo
they are both String... so i would need to use equals
rather than ==
i got the answer when i did it
thanks ya!!
 
Adam Nace
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by catherine matthews:
bingo
they are both String... so i would need to use equals
rather than ==
i got the answer when i did it
thanks ya!!


Not just in the case of String, either. Don't forget that ALL objects should be compared for equivalence using Object.equals, unless the EXACT reference equality is what you want.

Also, I wondered about the condition statement (duplicates > 1). Shouldn't this have been (duplicates >= 1) ?

- Adam
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic