Tag: Generics

How to Shuffle or Randomize a List in Java

In this post, we will discuss how to shuffle or randomize a List in Java using Fisher–Yates shuffle algorithm and shuffle() method provided by the Collections class.

How to Get Slice of a Stream in Java

In this post, we will see how to get slice of a stream in Java. In other words, we need to get a new stream of elements between two specified positions.

Convert HashMap to TreeMap in Java

In this post, we will see how to convert HashMap to TreeMap in Java. The resultant TreeMap should contain all mappings of the HashMap, sorted by their natural ordering of keys.

Concatenate Multiple Lists in Java

In this article, several methods to concatenate multiple lists in Java into a single list are discussed using plain Java, Java 8, Guava Library and Apache Commons Collections.

Convert a Set to Stream in Java 8

In this post, we will see how to convert a set to stream in Java 8. We will also learn how to apply filters on a stream and convert stream back to a set or list.