Collections tools

Collections tools

1 Introduction
java.utils.Collections is a collection tool class, used to operate collections.

2 Commonly used API
public static <T> boolean addAll(Collection<T> c, T... elements): Add some elements to the collection.
public static void shuffle(List<?> list): Shuffle the order, shuffle the order of the collection.
public static <T> void sort(List<T> list): Sort the elements in the collection according to the default rules.

3 use

public class

Demo01 {

public static void
main

(String[] args) {
ArrayList<String> arrayList =

new

ArrayList<>()

;

Collections. addAll (arrayList

,
"C"
,
"B"
,
"E"
,
"A"
,
"D"

)

;

System.

out

.println(

"Elements added to the collection:"

+arrayList)

;

Collections. shuffle (arrayList)

;

System.

out

.println(

"Disrupt the order of elements in the collection:"

+arrayList)

;

Collections. shuffle (arrayList)

;

System.

out

.println(

"Disrupt the order of elements in the collection:"

+arrayList)

;

Collections. sort (arrayList)

;

System.

out

.println(

"The sorting results are as follows:"

+arrayList)

;

}
}

For more technical information, please pay attention to: gzitcast