-3

I have two sets, each one contains Words(String)

Set <String> Set1= words1.keySet();
Set <String> Set2= words2.keySet();

I know the set is unordered , but i want to check if the First 5 elements of the both sets are equal or not , then check the next 5 elements .. etc any one can guide me ..

Yousef Ahmad
  • 63
  • 1
  • 3
  • 10

1 Answers1

1

Although you should DIY but here's the code:

    int count = 0;
            for(String s : keysDoc1)
            {
                if(keysDoc2.contains(s))
                    count++;
            }
//print count;

EDIT: Alternative approach

Set<String> c = keysDoc1;

        c.retainAll(keysDoc2); //remove uncommon elements from c

        System.out.println(c.size());
Shubhendu Pramanik
  • 2,711
  • 2
  • 13
  • 23