Tag: java collections algorithms

Common Elements Existence disjoint()

August 28, 2011 · 2 min read
The method, **disjoint()**, of [Collections class](http://way2java.com/collections/collections-api-methods/) 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](http://way2java.com/collections/list-fundamentals/) or [maps](http://way2java.com/collections/interface-map-tutorial/) or [sets](http://way2java.com/collections/interface-set-tutorial/).

Java Swap two elements with swap()

August 18, 2011 · 1 min read
The [Collections](http://way2java.com/collections/collections-api-methods/) 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.

Java Collections API Methods

August 11, 2011 · 6 min read
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](http://way2java.com/collections/java-interface-collection/) from which almost all data structures are derived, commonly known as [collection framework](http://way2java.com/collections/java-collections-framework/). **Collections** class contains many [static methods](http://way2java.com/oops-concepts/static-keyword-%e2%80%93-philosophy/) with which data structures manipulation becomes easier. I can say only word: Collections class is a boon (gift by the designers) to data structures which you too accept when you go through all the example codes given here under. I say boon because the lots of trouble you encountered with laborious coding of loops in C/C++ to manipulate DS elements is overcome with a simple method call. This is the best place to prove Java is simple language to practice.