java collections algorithms

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 »

Java Swap two elements with swap()

The Collections method swap() is very useful to swap two values in a programming code. For example, the prices of two different dates can be swapped. This method comes into existence with JDK 1.4. Following is the method signature of swap() method static void swap(List list1, int index1, int index2): List list1 elements at index …

Java Swap two elements with swap() Read More »

Java Collections API Methods

A small confusion comes to a novice at this juncture between collection and collections. Both are very different. Collection is an interface and Collections is a class, both from java.util package. Collection is the root interface from which almost all data structures are derived, commonly known as collection framework. Collections class contains many static methods …

Java Collections API Methods Read More »