java - Intersection of two sets -
this question has answer here:
is easy way intersection of 2 sets? have:
set<long> set1 = {1,2,3} set<long> set2 = {2,3,4}
and looking or method like:
set<long> intersection = new hashset<>(); intersection.intersect(set1, set2);
and intersection.tostring() produce me set contains {2,3}
you can use retainall()
.
note modify 1 of collections might want create copy first.
Comments
Post a Comment