java collection methods

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 »

Java Filling List elements with fill()

With the Collections 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. Following is the method signature static void fill(List list1, Object obj1): Replaces all the elements of list1 with obj1. …

Java Filling List elements with fill() 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 »

Java Interface Collection

Java Interface Collection Summary: Java Interface Collection is the super most interface from which almost all DS are derived. Explained the API in simple terms for a very beginner. Collection interface forms the base from which many data structures (almost all) are derived. The data structures derived from Collection interface are known as collections framework. …

Java Interface Collection Read More »