Public class extends Implements NavigablesetTreeSet implementations are based on TreeMap, and the order of the elements depends on the natural order of the elements or the comparer provided when they are created.For basic operations, the time complexity of add, remove, and contains is Logn.is not thread-safe, if it must be synchronized in a multithreaded environment, it can be synchronized with an object as a lock, or using Collections.synchronizedsortedset (new
by the key. By default, It is the sort of key values in ascending order. You can also specify the sort comparator. When you use Iterator to traverse the TreeMap, the obtained records are sorted in ascending order.
Generally, HashMap is used most often. The key-value pairs stored in HashMap are random when they are retrieved. It stores data based on the key's HashCode value, you can directly obtain its value based on the key, with fast access speed. HashMap is the best choice for inserting, dele
Set, List, Map, and setmap in Multi-learning JavaFor a long time, the List of data that has been used in the Code is mainly List, and it is all ArrayList. This is enough. ArrayList is a packaging tool class used to implement dynamic arrays, so that code can be pulled in and pulled out during code writing, and iterative traversal is quite convenient. I also don't know when the tool classes such as HashMap and HashSet will often appear in the code. It should be said that there are more hashmaps, a
Java Collection programming focus
I. Common Array Operations
Import java. io. *; import java. math. *; import java. util. *; public class Main {private static int [] a = new int [20]; public static void print () {for (int I = 0; I Ii. set
HashSet: there are no duplicates. The types added can be different.
TreeSet: there are no duplicates. The added fields must be of the same type, because they are automatically sorted.
HashSet:
Import java. io. *;
The Set interface allows you to conveniently Save the specified type in a variable as a Set type. Set is a Collection that does not contain repeated elements. More specifically, Set does not contain any element pair that meets e1.equals (e2), and contains at most one null element. The underlying storage implementation of the Set interface depends on the implementation of Map. It can be said that the management of elements in the Set interface is the management of keys in the Map. The following d
The Java Collection Framework implements common basic data structures, such as: collections, linear tables, queues, stacks, mapping tables, and so on.is the class diagram for the collection framework:Java Collection framework is mainly composed of collection interface and map interface, collection interface has sub-interface list, Set, queue interface. Common collection classes are: ArrayList, LinkedList, HashSet, TreeSet, HashMap, TreeMap, and some l
1. Keyboard Input 5 Student information (name, language score, Math score, English score), according to the total score from high to low output to the console:Analysis: A: Define Student ClassB: Create a TreeSet collectionC: How to achieve the total score from high?D: Keyboard input 5 Student informationE: Traversing the TreeSet collection2. code example:(1)Student. Java:1 Packagecn.itcast_08;2 3 Public
Attention:If HashSet stores custom objects, be sure to override Hashcode () equals ()If TreeSet stores custom objects, let the class that the element belongs to implement the natural sort interface comparable, and override CompareTo ()/ Let the constructor of the collection receive a sub-class object of the comparer interface Comparatorstructure:Set:|--hashset (The underlying structure is a hash table (hash table: The element is an array of linked lis
,hashmap inside the key value of the pair when it is taken out is random, it according to the hashcode value of the key to store data, according to the key can directly get its value, with fast access speed. HashMap is the best choice for inserting, deleting, and locating elements in a map.The treemap takes out the sorted key-value pairs. But if you want to traverse the key in natural order or in a custom order , TreeMap is better.Linkedhashmap is a subclass of HashMap, if you need to output the
element's small top heap, keeps inserting the element inside. The last element in the heap is the smallest element we ask for. The benefit of this solution is that the elements in the array are not moved. But it opens up extra space.Java solution based on solution Three: the process of building a K-heap is too complex, and Java provides a lot of collections that we can use to scatter! The following code is a small top heap I built with TreeSet, why u
first, set sort (method one)concept: The Java.lang.Comparable interface works when a class has a natural order. The object collection is assumed to be of the same type, which allows the collection to be sorted into natural order. The int compareTo (T obj) method in this interface compares the current instance object with Object obj, returns a negative value if it precedes the object obj, returns 0 if the two objects are in the same position in the sort, or returns a positive value if it is behin
-class features of the list collection:ArrayList's underlying data structures are arrays, fast queries, additions and deletions, thread insecurity, high efficiencyVector's underlying data structures are arrays, fast queries, additions and deletions, thread safety, low efficiencyLinkedList the underlying data structure is linked list, query slow, and delete quickly. Thread insecure, high efficiencyUnique features of vector:1) Add featurespublic void addelement (Object obj)2) Get FeaturesPublic Ob
In the following method: method 2 has been confirmed correct! You can specify the sorting method: In hibernate, the Set set is used for one-to-many and multi-to-many associations, but sometimes objects in the Set set need to be sorted in the business. Of course, we can change the Set set to the list set to store objects, but if we use the list, we need to add a new field in the database. I don't want to change the data structure, so, how should we sort the set?
Department table (Dept) ---------
coefficient.
Stack-as a stack operation, this operation inherits from the vector and provides the push, pop, and peek methods. Peek does not pop up to obtain the last element object based on the data size.
Ii. Set mainly includes hashset and treeset
Hashset-This class is inherited from the set interface. Compared with the list, it means that the elements added internally cannot be repeated, of course, from the perspective of name hash, the hash algor
key in Map is used.
Set common methods. For details, refer to the Java API
Add (E): If no specified element exists in the set, add this element.
AddAll (Collection
Clear (): removes all elements in this set.
Contains (Object o): returns true if set contains the specified element.
ContainsAll (Collection
Equals (Object o): Compares the equality between the specified Object and the set.
IsEmpty (): returns true if set does not contain elements.
Iterator (): The iterator tha
) = false, and set has a maximum of null elements.The Set constructor has a constraint that the imported collection parameter cannot contain duplicate elements. Note: You must be careful when operating mutableObject ). If a variable element in a set changes its state, object. Equals (object) = true may cause some problems.The two general set implementations are hashset and treeset. It is very simple and clear to decide which one to use. Hashset is muc
1. PairListSelect
Both arraylist and sorted list implement the list interface, and the vector is also, but it is no longer used. Arraylist is preferred.
2.Set,
You can select treeset, hashset, or javashashset. The performance of hashset is always better than that of treeset (especially the most common operations for adding and querying elements ). The only reason tre
1.Collection List Set Map differential memoryThese represent the collection in Java, where the main element is whether the elements are ordered, whether they can be repeated to distinguish between memory, in order to properly use, of course, there are synchronization differences, see the previous article related.
Ordered No
Allow elements to repeat no
Collection
Whether
Is
List
Is
Is
Set
Abstractset
definition:① red links are left links② no node is connected to two red links at the same time③ The tree is perfectly black balanced, that is, any empty link to the root node on the path of the same number of black links.Keep a red-black tree balanced by rotating and color-flipping these balancing operations. the red-black tree does not seek "complete balance"-it only requires partial balancing requirements, reducing the need for rotation, thus improving performance.Refer to this blog post for d
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.