Problem: How to use Java List in a thread-safe way? It can be synchronized manually or you can use a wrapper method from Java Collections Framework. Learn how to use it correctly.
Problem: How to swap elements in Java List? Swap operation is very often used when implementing sorting. In the following example we show Java List swap operation from Java Collections Framework.
Problem: How in Java sort List? Java allows to sort list elements using their natural ordering or using custom Comparators. In the following example we present both approaches.
Problem: How to create Java singleton List is the easiest way? Java Collections Framework has a couple of handy methods to create singleton List, singleton Set, and singleton Map. See the example.
Problem: How in Java randomly shuffle an array or List? This common problem can be solved with Java Collections Framework as in the following example.
Problem: How in Java rotate List elements or move an element to specified position? Java Collections Framework has nice solutions for this problem.
Problem: How to sort Java array/List in reverse order? It can be done with Reverse Comparator that can be created using Java Collections API. This example demonstrates its usage with Java Arrays and Lists.
Problem: In Java some Map implementations have corresponding Sets, but not all of them. How to create a Set with the same ordering, concurrency, and performance characteristics?
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…
Problem: 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…