The ensureCapacity(int minCapacity) method of java.util.ArrayList class increases the capacity of this ArrayList instance if necessary to ensure that it can hold at least the number of elements specified by the minimum capacity argument.
Swapping the elements of the ArrayList
- Create a new arraylist arraylist al1.
- Add elements to al1 using add() method.
- Use Collections.swap() method to swap the required elements of al1.
public boolean removeAll(Collection<?> c)
It removes all the elements in the list that are not contained in the specified list. [Read more…]