In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces what Collection and Map are in the data type. The content is very detailed. Interested friends can use it for reference. I hope it will be helpful to you.
Collection interface type 1 List: ordered (in and out the same order), elements are indexed (corner marks), elements can be repeated. Interface type 2 Set: elements cannot be repeated, sequence is not guaranteed by default, and sequential implementation is provided. Interface type 3 Queue: linear table queue, orderly, first-in-first-out data structure. |-- AbstractCollection: implements the Collection interface, cannot create an instance, and needs to use its sub-implementation class |-- AbstractList: implements the List interface, orderly, abstract class, and powerful |-- ArrayList: internally is an array data structure, which is asynchronous (non-thread safe). Instead of Vector. Query speed is fast |-- LinkedList: the interior is a linked list data structure, which is out of sync. The speed of adding and deleting elements is very fast |-- Vector: inside is an array data structure, which is synchronized. Add or delete, the query is very slow, and it is no longer recommended |-- Stack: stack, first in, last out, no longer recommended |-- AbstractQueue: implements the Queue API, orderly, and the iterative order can be sorted naturally or in the custom class by implementing the "Comparable" API to override the Comparator method for sorting. When the element in the queue is null, an exception is thrown instead of returning a false or null word class. The offer () method must be defined, which does not allow null values to be inserted. Priority queues that rely on natural order are not allowed to insert incomparable objects yet |-- PriorityQueue: priority queues. Each time the queue is taken out of the queue, the elements with the highest priority can be sorted automatically, and the stored elements are not arranged in the order in which the elements are added. Instead, it is arranged internally according to the size of the elements |-|-- ArrayDeque: it implements Deque (double-end queue, a sub-interface of Queue), which is orderly and non-thread safe, and is recommended to be used as a stack or queue. Adding, deleting and taking values of null elements are not allowed to have two sets of interfaces. They all have the same function, but the difference is that the handling of failure cases is different. One set of interfaces will throw an exception when it fails, and the other set will return a special value (false or null) if it fails. |-- AbstractSet: implements the Set API, unordered, overrides the equals () and hashCode () methods |-- TreeSet: implements the navigable interface NavigableSet (Set subinterface (SortSet subinterface)), which is based on TreeMap and is orderly. It can be sorted naturally or in a custom class by implementing the "Comparable" API overriding the Comparator method for sorting. |-- HashSet: the Set interface is implemented, unordered. Before using the hash algorithm to operate the element, the hashcode method on the element will be called first. If the hash code collides, the equlas method will be triggered to determine whether to agree with the object JDK: if two objects are equal, their hashcode values must be equal. If the hashcode values of two objects are equal, the objects are not necessarily equal |-- LinkedHashSet: bi-directional linked list structure, non-thread-safe, based on LinkedHashMap, in order, the sequence is the insertion order of the list collection, you can complete the addition, deletion, modification and query of elements. List: a unique common method: a common feature is that they can operate angle marks. 1, add void add (index,element); void add (index,collection); 2, delete Object remove (index): 3, modify: Object set (index,element); 4, get: Object get (index); int indexOf (object); int lastIndexOf (object); List subList (from,to) The difference between LinkedList and ArrayList: LinkedList uses bi-directional linked lists. If you need to add or delete this kind of data structure (collection), it is more efficient to use LinkedList. ArrayList realizes the data structure based on dynamic array, while LinkedList is based on bi-directional linked list. The data structure of get and set,ArrayList is better than LinkedList for random access, because LinkedList is based on pointer movement. When ArrayList wants a get (int index) element, it returns the element at the index location directly, while LinkedList needs to find it through a for loop, although LinkedList has optimized the lookup method, such as index
< size / 2,则从左边开始查找, 反之从右边开始查找,但是还是比ArrayList要慢。这点是毋庸置疑的。 ArrayList想要在指定位置插入或删除元素时,主要耗时的是System.arraycopy动作,会移动index后面所有的元素; LinkedList主耗时的是要先通过for循环找到index,然后直接插入或删除。Set存放不重复元素,默认不能保证顺序,提供有顺序 /--HashSet:采用hash算法,无序 操作元素前,会先调用元素身上的hashcode方法,如果散列码发生碰撞,会触发equlas方法用于判定是否为同意个对象 JDK规定:如果两个对象相等,他们的hashcode值必然相等,如果两个对象的hashcode值相等,对象不一定相等 /--LinkedHashSet:采用hash算法,有序 /--TreeSet: 采用Tree算法,有序Map::映射类,key-->Value, interface, corresponding to collection |-- AbstractMap: implements Map interface |-- HashMap: unordered, unsafe, but collection framework provides methods to guarantee HashMap synchronized |-- LinkedHahMap: orderly, unsafe, iterative order can be insert order or access order |-- HashTable: disordered, safe, almost equivalent to HashTable, but thread safety also takes into account performance issues. ConcurrentHashMap should be used. The same key value defaults to the same object. The iteration order can be sorted naturally or by implementing the "Comparable" API overriding the Comparator method in a custom class |-- EnumMap: enumerated mapping, () is enumerated class, ordered, iterative order is enumerated order |-- IdentityHashMap: it is not a general implementation of Map and allows the same key values to be stored. Only when two key addresses are the same are considered equal unordered, unsafe, allowing key and value to be the difference between nullashTable and HashMap: HasnMap is almost completely equivalent to HashTable HashTable thread safety, all operations are thread synchronization, use HashMap without thread synchronization, if high concurrency, thread safety should also take into account performance issues, should be used ConcurrentHashMap. HashMap is non-thread safe. HashMap allows value of null, key HashTable of null allows value of null, key iterative operation of null is not allowed: HashMap fails quickly, HashTable security fails so much about what Collection and Map are in data types. I hope the above can help you and learn more. If you think the article is good, you can share it for more people to see.
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.