Tag: java collection methods

Immutable List with nCopies()

September 1, 2011 · 2 min read
The **nCopies()** method of [Collections class](http://way2java.com/collections/collections-api-methods/) returns an **immutable object** of List. The **immutable object** cannot be modified. It is read-only. If tried to modify, the JVM throws [UnsupportedOperationException](http://way2java.com/collections/unsupportedoperationexception/).

Java Filling List elements with fill()

August 19, 2011 · 1 min read
With the [Collections](http://way2java.com/collections/collections-api-methods/) **fill()** static method (Collections methods are known as algorithms), a data structure can be filled up (or replaced) with one element. After this method call, the data structure will have the same element.

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.
← Prev
Page 1 of 2
Next →