How can I compare two hash sets in java ? My first hash sets looks like below.
static Set<String> nounPhrases = new HashSet<>();
Above hash set contains elements like this.
List of Noun Parse : [java, jsp, book]
2nd hash set
static Set<String> nounPhrases2 = new HashSet<>();
List of Noun Parse : [web, php, java,book]
Note - I need to check if there are equal nouns in both sets. and if they have similar nouns then I need to do another task
This is a wheel already invented.
Set#equals()
compares sets in the way you would expect:
set1.equals(set2)
If you want two Set variables that are both null to be "equal", then use:
Objects.equals(set1, set2)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With