• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to compare this? please help

 
catherine matthews
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
cde=1
efg=1

how to i go about... please help me.... so far this is what i have done....
 
Ken Blair
Ranch Hand
Posts: 1078
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic