In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly shows you "how to use java collection framework", the content is simple and easy to understand, organized clearly, I hope to help you solve doubts, let Xiaobian lead you to study and learn "how to use java collection framework" this article bar.
Collections are widely used in java, and collection classes are an important part of the java.util package, which allows elements to be grouped in various ways and defines methods to make them easier to manipulate. Java collection class is Java will be a number of basic and highly used basic classes encapsulated and enhanced in the form of a class to provide. Collection class is a class that can store multiple objects in it. Different collection classes have different functions and characteristics, suitable for different occasions, and used to solve some practical problems.
The collection framework is designed to meet several goals
1. The framework must be high performance. The implementation of basic sets (dynamic arrays, linked lists, trees, hash tables) must also be efficient. 2. The framework allows different types of collections to work in similar ways with a high degree of interoperability. 3. Extension and adaptation of a set must be simple. To this end, the entire collection framework is designed around a standard set of interfaces. You can directly use standard implementations of these interfaces, such as LinkedList, HashSet, and TreeSet, etc. You can also implement your own collections through these interfaces.
The Java collection framework diagram is as follows:
As you can see from the collection framework diagram above, the Java collection framework mainly consists of two types of containers, one is a collection, which stores a collection of elements, and the other is a map, which stores key/value pair mappings. Collection interface has three subtypes, List, Set and Queue, and then some abstract classes, and finally the concrete implementation classes, commonly used are ArrayList, LinkedList, HashSet, LinkedHashSet, HashMap, LinkedHashMap and so on.
Java collections believe that everyone has used them more or less, and here is not a specific introduction. The following is a look at the differences between these collections:
big difference
Providing so many collection classes, in general, is to achieve different functions, such as Set elements can not be repeated, List can be repeated, Queue first-in first-out, do not allow random access to elements in the queue, Map contains key value pairs, each of which can be subdivided into some classes that can be sorted, or support concurrency, etc.
Like LinkedList, List and Queue are implemented, which can be used as first-in first-out queues, double-ended queues, and stack capabilities.
LinkedHashSet inherits HashSet, ArrayDeque implements Queue, and arrays implement double-ended queues.
Stack is based on Vector implementation. TreeSet is based on TreeMap implementation and supports sorting.
ArrayList, HashSet, LinkedHashSet, HashMap, LinkedHashMap, Hashtable, LinkedList, Vector, etc.
ArrayList: This class also implements the List interface, implements variable size arrays, and provides better performance when accessing and traversing elements randomly. This class is also asynchronous and should not be used in multithreaded situations. ArrayList grows by 50% of its current length, and insertions and deletions are inefficient.
HashSet: This class implements the Set interface. Duplicate elements are not allowed. The order of elements in the collection is not guaranteed. Elements with null values are allowed, but only one element is allowed.
LinkedHashSet: hash table and linked list implementation of the Set interface with predictable iteration order.
HashMap: A hash table that stores key-value mappings. This class implements the Map interface, stores data according to the HashCode value of the key, has a fast access speed, allows at most one record of the key to be null, does not support thread synchronization.
LinkedHashMap: Inherited from HashMap, sorts elements using their natural order.
Hashtable: A subclass of the Dictionary class, located in the java.util package. is thread-safe;
LinkedList: This class implements the List interface and allows null elements. Mainly used to create linked list data structure, this class has no synchronization method, you need to implement access synchronization yourself, the way is to create a synchronization List when creating a List, such as:
List list = Collections.synchronizedList(newLinkedList(…));
Vector: This class is very similar to ArrayList, but this class is synchronous and can be used in multithreaded situations. This class allows setting the default growth length, and the default expansion method is twice the original.
The above is "java collection framework how to use" all the content of this article, thank you for reading! I believe that everyone has a certain understanding, hope to share the content to help everyone, if you still want to learn more knowledge, welcome to pay attention to the industry information channel!
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.