Java Programming Tutorials

Java programming tutorials with many code examples!

Java synchronized List

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.

Read More

Share with the World!

Java List swap

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.

Read More

Share with the World!

Java sort List

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.

Read More

Share with the World!

Java singleton List

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.

Read More

Share with the World!

Java randomly shuffle

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.

Read More

Share with the World!

Java rotate List

Problem:

How in Java rotate List elements or move an element to specified position? Java Collections Framework has nice solutions for this problem.

Read More

Share with the World!

Java reverse Comparator

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.

Read More

Share with the World!

Java reverse List

Problem:

How to reverse Java List when List doesn’t have such method? As usually the solution is in Java Collections API.

Read More

Share with the World!

Java Collections newSetFromMap

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?

Read More

Share with the World!

Java Collections nCopies

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…

Read More

Share with the World!