Java collections programs

Immutable List with nCopies()

The nCopies() method of Collections class returns an immutable object of List. The immutable object cannot be modified. It is read-only. If tried to modify, the JVM throws UnsupportedOperationException. Following is the method signature static List nCopies(int n1, Object obj1): Returns an immutable list containing n1 elements of the object obj1. That is add() method …

Immutable List with nCopies() Read More »

Common Elements Existence disjoint()

The method, disjoint(), of Collections class returns true if the two data structures under comparison does not have any elements in common. At least, one element is common in the both, it returns false. disjoint() method is very useful to compare (to know the existence of common elements) two lists or maps or sets. Following …

Common Elements Existence disjoint() Read More »