Common elements in two lists

Use Collection#retainAll(). listA.retainAll(listB); // listA now contains only the elements which are also contained in listB. If you want to avoid that changes are being affected in listA, then you need to create a new one. List<Integer> common = new ArrayList<Integer>(listA); common.retainAll(listB); // common now contains only the elements which are contained in listA and … Read more

How may I reference the script tag that loaded the currently-executing script?

How to get the current script element: 1. Use document.currentScript document.currentScript will return the <script> element whose script is currently being processed. <script> var me = document.currentScript; </script> Benefits Simple and explicit. Reliable. Don’t need to modify the script tag Works with asynchronous scripts (defer & async) Works with scripts inserted dynamically Problems Will not … Read more

Deleting array elements in JavaScript – delete vs splice

delete will delete the object property, but will not reindex the array or update its length. This makes it appears as if it is undefined: > myArray = [‘a’, ‘b’, ‘c’, ‘d’] [“a”, “b”, “c”, “d”] > delete myArray[0] true > myArray[0] undefined Note that it is not in fact set to the value undefined, … Read more