The collection utilities Arrays and Collections Java Fundamentals -

A .Arrays categories:
conventional method (the array into a set):
public static List asList (A T ...) is equivalent to public static List asList (T [] a).
Here Insert Picture Description
Here Insert Picture Description
Note: List object is obtained by a method Arrays.asList length is fixed and can not increase nor decrease.
the ArrayList asList method returns the object, but not java.util.ArrayList Arrays internal class object class.

Here Insert Picture Description
Here Insert Picture Description
two categories .Collections
Collections class: encapsulates Set, List, Map . the method of operating a tool of
acquiring objects empty set (no element of the set, note collection is not null):
Here Insert Picture Description
Here Insert Picture Description
Here Insert Picture Description

Commonly used collections:
HashSet / ArrayList / HashMap is thread safe, unsafe in a multithreaded environment
have acquired a set of thread-safe method in the Collections class:
List List = Collections.synchronizedList (new new ArrayList ());
when the iterations do have to use the synchronized.
the synchronized (List) {
the TODO
}

Set set = Collections.synchronizedSet(new HashSet());

Map map = Collections.synchronizedMap(new HashMap());
Here Insert Picture Description
三.
Here Insert Picture Description
四.Here Insert Picture Description

Published 99 original articles · won praise 2 · Views 2598

Guess you like

Origin blog.csdn.net/weixin_41588751/article/details/105313143