Learn to find the union between two arrays in Java using HashSet class. In set theory, the union (denoted by U) of a collection of sets is the set of all elements in the collection. For example, the union of two sets A and B is the set of all the elements which are either […]
Learn to find the intersection between two arrays in Java using HashSet class. An intersection is a group of common items that belong to two different sets. To get the intersection of two arrays, follow these steps: Push first array in a HashSet instance. Use retainAll() method to retain only elements which are present in […]
Learn to remove duplicate elements in Array in Java using different techniques such as LinkedHashSet from Collections framework and using a temporary array.
Learn how to check if an arraylist contains a value in Java with example. Also, learn to check if array contains an element, along with index of element in array. 1. Java ArrayList Contains Example To check if an ArrayList contains an element, use ArrayList.contains(element) method. contains(element) method does not take null argument, and will […]
Learn to create clone of an array in Java with example. Clone creates shallow copy of an array. Also learn to create array deep copies. Array Clone – Shallow Copy In Java, to create clone of array, you should use clone() method of array. It creates a shallow copy of array. Cloning always creates shallow […]