In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces "the basic introduction and usage of Collection interface". In daily operation, I believe many people have doubts about the basic introduction and usage of Collection interface. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "basic introduction and usage of Collection interface". Next, please follow the editor to study!
Collection subinterface
List
List is an ordered collection that controls the order in which elements are inserted and can also access operational elements directly based on the subscript.
List usually allows the inclusion of duplicate elements, including duplicate null elements.
Set
Set is not allowed to contain duplicate elements, and the underlying layer is implemented through Map.
Usually Set is unordered and does not guarantee the insertion order of elements, with the exception of partial implementation (LinkedHashSet).
Queue
Queue (queue) is a collection designed to save elements before processing.
In addition to the basic operations in the Collection interface, Queue provides other insert, get, and check operations; each operation has two forms: one is to throw an exception when the operation fails, and the other is to return a special value (null or false) if the operation fails.
Queue usually does not allow the insertion of null elements, while some implementation classes, such as LinkedList, do not prohibit the insertion of null values. However, we still need to avoid inserting null elements, because poll () returns null when Queue is empty.
Collection source code parsing public interface Collection extends Iterable {/ * * returns the number of elements in the current collection If the number of elements in the collection is greater than Integer.MAX_VALUE, return Integer.MAX_VALUE * * / int size () directly; / * * return whether the current collection does not contain any elements * * / boolean isEmpty (); / * * return an Object array containing all elements in the current collection * * / Object [] toArray () / * * returns a specified type T array containing all elements in the current collection * * / T [] toArray (T [] a); / * * returns whether the current collection contains the specified element o * * / boolean contains (Object o); / * * returns whether the current collection contains all elements in the specified collection c * / boolean containsAll (Collection c) / * * add elements e * * / boolean add (E e) to the current collection; / * * add all elements in the specified collection c to the current collection * * / boolean addAll (Collection c); / * * keep only the elements that exist in both the current collection and the specified collection c * / boolean retainAll (Collection c) / * * remove all elements in the current collection * * / void clear (); / * * remove all elements from the current collection that meet the specified criteria filter New method of JDK1.8 * * / default boolean removeIf (Predicate
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.