The following is a discussion of array sorting and search capabilities, while a common approach is to implement the comparable interface, a method that needs to be implemented through Java generics. Here's a step-by-step explanation of why, and how
One, Set
set: Focus on the unique nature of the system set to know whether something is close to the collection and does not store duplicate elements
Used to store elements that are unordered (not necessarily the same in the order in which they
A Java array is a Java object. The length of an array is fixed. Only data of the same type can be stored in the same array. An array can store data of the basic type, you can also store reference data. When creating an array object, you must specify
Java design mode, java design mode pdf
[This article is my own learning notes. You are welcome to repost it, but please note the Source: http://blog.csdn.net/jesson20121020]
We implement a sorting class so that it can sort the elements in the
Collections in Java are divided into single-column and double-row collections.Tree system of single-column collections:---------| Collection the root interface of a singleton collection ------------| list if it is a collection class that implements
--- | Collection: a single column set describes the commonality of all interfaces)
--- | List: the storage sequence can be repeated.
--- | ArrayList:
Array Implementation, fast search, slow addition/Deletion
Because it is an array implementation,
[JAVA & #183; elementary]: 19. Container classOverview
A container is a collection of data.
(Java provides an interface to specifically constrain the implementation classes of our containers)
Set: does not allow duplicate objects toenter the
Java Collection framework 1, java Collection framework1. Summary
All collection classes are located under the java. util package. Only objects can be saved in the collection (the referenced variables of objects are saved ). (Arrays can save basic
In business logic, we often need to sort the list as follows:Collections.sort (l);If the elements in L are of type string, you will find that the sort method will be sorted alphabetically. If the elements in L are of type date, the sort method is
Zookeeper
A container is a series of class instances provided by Java API, used to store objects in programs. A container can manage the lifecycle of an object and the dependency between the object and the object. Java container classes include List,
*treeset compared to hashset, the tree set is an ordered set, and for the tree set traversal, each value is automatically rendered in sorted Order.* TreeSet is currently using a red-black tree, each time an element is added to the tree, it will be
Same
Both comparable and comparator are used to implement object comparisons, sorting
To compare and sort objects, you need to implement comparable or comparator interfaces
Comparable and comparator are all Java interfaces.
1: Set 2 Collection (Single column collection) 3 List (ordered, repeatable) 4 ArrayList 5 The underlying data structure is an array, query fast, delete and subtract slowly 6 Thread insecure, high efficiency 7 Vector 8 The underlying data
Relationship DiagramSingle-Instance set system---------| Collection The root interface of a singleton collection--------------| List inherits the collection Interface , features: orderly, repeat . ------------------| Arrarylist Inherit the list
First: Comparable sort interface If a class implements the comparable interface, it means "this class supports sorting." Assuming "There is a list (or array) of elements that are classes that implement the comparable interface, the list (or array)
[This is my own study notes, welcome reprint, but please specify the source:http://blog.csdn.net/jesson20121020]
We implement a sort class that enables the ordering of elements in an array, as well as the ability to print arrays. As shown below,
Comparator,comparable interface differences between object sorting:
Comparable is a general-purpose interface that users can implement to perform their own specific comparisons, while comparator can be seen as an implementation of an algorithm that
the difference between comparable and comparatorThe fundamental difference is that the 1.Comparable is an internal comparator, and the comparator is an external comparator Package packages are
"To achieve a natural ordering, the object collection must implement the comparable interface and override the CompareTo () method The general requirements describe the "main conditions", such as: Sort by name length. Note the secondary conditions
A List l may be sorted as follows:
Collections.sort (l);
If the list is composed of String elements, it is sorted alphabetically by dictionary; If it is made up of Date elements, it will be sorted in chronological order. How does Java know how to
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.