-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating
Learn Java 17 Programming - Second Edition
By :
There are two classes with static methods handling collections that are very popular and helpful, as follows:
java.util.Arraysorg.apache.commons.lang3.ArrayUtilsWe will briefly review each of them.
We have already used the java.util.Arrays class several times. It is the primary utility class for array management. This utility class used to be very popular because of the asList(T...a) method. It was the most compact way of creating and initializing a collection and is shown in the following snippet:
List<String> list = Arrays.asList("s0", "s1");
Set<String> set = new HashSet<>(Arrays.asList("s0", "s1");
It is still a popular way of creating a modifiable list—we used it, too. However, after a List.of() factory method was introduced, the Arrays class declined substantially.
Nevertheless, if you need to manage arrays, then the Arrays class may...