File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes how to compare this? please help 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 compare this? please help" Watch "how to compare this? please help" New topic

how to compare this? please help

catherine matthews
Ranch Hand

Joined: Jan 22, 2006
Posts: 78
i need to see the content of 2 arrays
if there is repitition i need to take only one occurance...
Lets say i have 2 arrays arr and arr2 and their content is as below....
arr[0]=abc arr2[0]=123
arr[1]=cde arr2[1]=102
arr[2]=efg arr2[2]=789
arr[3]=abc arr2[3]=123
arr2[0]=abc arr2[4]=456

i need need to count how mnay times an element of arr is being used by different arr2.

so for this set of example... i need to eliminate arr2[3] because it is the same as arr2[0]...
thus the elememt in arr would have counts like this
abc = 2

how to i go about... please help me.... so far this is what i have done....
Ken Blair
Ranch Hand

Joined: Jul 15, 2003
Posts: 1078
I'm sorry I don't fully understand your question. It sounds like you may want to make use of a java.util.Set though. A Set does not allow duplicate entries, if you were to dump the contents of your array into a Set you would eliminate any duplicates presuming the contents are not primitives and have appropriate equals() methods.

Are you attempting to merge the arrays at all?
I agree. Here's the link:
subject: how to compare this? please help
It's not a secret anymore!