collections java

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 »

Shuffle elements randomly with shuffle()

The shuffle() method of Collections class shuffles the elements randomly. The same method shuffle() called multiple times gives different order of elements. The algorithm is developed by designers with some randomness basing on a seed value. Shuffling is useful in game development. For example, using shuffle() method, the playing cards can be shuffled. This method …

Shuffle elements randomly with shuffle() Read More »