It's not a secret anymore!*
The moose likes Beginning Java and the fly likes how to get duplicates? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "how to get duplicates?" Watch "how to get duplicates?" New topic
Author

how to get duplicates?

catherine matthews
Ranch Hand

Joined: Jan 22, 2006
Posts: 78
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

Joined: Feb 07, 2005
Posts: 2367
Look carefully at what sk and s1 indicate.
[ July 15, 2006: Message edited by: Keith Lynn ]
catherine matthews
Ranch Hand

Joined: Jan 22, 2006
Posts: 78
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

Joined: Jul 17, 2006
Posts: 117
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
 
Consider Paul's rocket mass heater.
 
subject: how to get duplicates?
 
Similar Threads
ArrayList
Searching through an array to find and print duplicate random numbers
getting Class cast exception
thread safety issue.......
RandomAccessFile help