How to compare the elements of a SortedSet to see how many elements of the two sets match

StackOverflow https://stackoverflow.com/questions/21532419

  •  06-10-2022
  •  | 
  •  

Вопрос

I'm writing a program that tests lottery pick programs for statistical analysis. I pretty much have an idea of how to store the data. My question is: how I can take two sortedsets of equal size (I have a method that checks that), compare them and return a number that represents the number of matching elements in both sets?

I can post my code, but really I have no idea what method to use. I want to know what way I'm going to solve this before I code too much. Should I use the hashcode method or some other way to attack this issue?

Это было полезно?

Решение

Set<String> intersection = new HashSet<String>(s1); 
intersection.retainAll(s2);
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top