How to calculate the intersection of two sets? [duplicate]

Use the retainAll() method of Set: Set<String> s1; Set<String> s2; s1.retainAll(s2); // s1 now contains only elements in both sets If you want to preserve the sets, create a new set to hold the intersection: Set<String> intersection = new HashSet<String>(s1); // use the copy constructor intersection.retainAll(s2); The javadoc of retainAll() says it’s exactly what you … Read more

Simplest code for array intersection in javascript

Use a combination of Array.prototype.filter and Array.prototype.includes: const filteredArray = array1.filter(value => array2.includes(value)); For older browsers, with Array.prototype.indexOf and without an arrow function: var filteredArray = array1.filter(function(n) { return array2.indexOf(n) !== -1; }); NB! Both .includes and .indexOf internally compares elements in the array by using ===, so if the array contains objects it will … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)