Problem: How to create a Java List with copies of the same element? Java Collections.nCopies(n, T) does that, but has its quirks. Read on…
Continue reading Java Collections nCopiesJava
Problem: Java has great support for Zip format and writing code in Java to zip/unzip file is really simple. Java 8 makes it even simpler. The following example shows how to zip and unzip file.
Continue reading Java zip fileProblem: Having a Java Collection find min/max values? As in many cases it can easily be done with Java Collections API. See the following example…
Continue reading Java Collection min/max valueProblem: When using legacy libraries sometimes you need to convert Java Enumeration to List to use it with modern code it comfortable way. Again Java Collections API comes to the rescue!
Continue reading Java Enumeration to ListProblem: How to find a first/last occurrence of sublist in Java List? As expected Java Collections API has a method for this. See the example for details.
Continue reading Java List sublistProblem: When working with legacy code, you need to convert Java Collection to Enumeration. This example shows how to do that using Java Collections API features!
Continue reading Java Collection to EnumerationProblem: In Java empty List/Collection is very often used to implement NullObject Pattern and make code more readable. See how on the following example.
Continue reading Java empty List/Collection and null checkProblem: Sometimes we want on Java List replace/fill all/selected elements. It can be done manually, but much better way is to reuse Java Collections API. See how!
Continue reading Java list replace/fill elementsProblem: Sometimes you have to in Java find/count occurrences of objects inside a Java Collection. It can be done manually, but vast Java Collections API provides a better way.
Continue reading Java find/count occurrencesProblem: How to check that a collection in Java contains any of elements from some other collection? It’s very common problem when working on Sets, but also applicable to Java Lists and other collections.
Continue reading Java contains any