1 > and > What's the difference
>
The
type T must implement the
Comparable interface, and the type of the interface is T. Only in this way can the instances of T compare size to each other. For example, if
TreeSet: You can sort the elements in the set collection.Example: Storing a custom objectImport java.util.*;/* Requirements: Store custom objects in the TreeSet collection-students want to sort by student's age */class student{private String
Comparablecomparable is the sort interface.If a class implements the comparable interface, it means "this class supports sorting." The class that implements the comparable interface supports sorting, assuming that there is now a list (or array) of
Storage structureFirst, the HashMap is stored based on a hash table. There is an array inside it, and when the element is to be stored, the hash value of its key is computed first, and the corresponding subscript of the element in the array is found
A few years ago when Java5 was not officially released, I saw some people write about new features in Tiger, and the first thing that hit me the most was generics (generics) and annotations (annotation), because they directly affected the
article author: Tyan
Blog: noahsnail.com 1. What is generics
Java generics (generics) is a new feature introduced in JDK 5, which allows you to use type parameters when defining classes and interfaces (type parameter), which are also called
Java generics-type eraseI. OverviewJava generics in the use of the process has many problems, such as the absence of List.class, list can not be assigned to list (non-covariant), Strange classcastexception and so on. Proper use of Java generics
First, Linkedhashset CollectionThere are sub-classes under HashSet linkedhashsetAPI documentation for Linkedhashset explanation:A hash table and a link list implementation of a Set interface with predictable iteration order. This implementation
The list implementation defined in the Java Collection Framework has vector,arraylist and LinkedList. These collections provide index access to the group of objects. They provide support for adding and removing elements. However, they do not have
TreeSet
Conditions
Same type
Design to sort
Comparable is natural (you can modify the case of a class)
Comparator is custom (in the case of a class cannot be modified) higher priority
Instructions for use:
Generally used is the natural sort, but
Comparableand is the Comparator interfaces provided by Java Core API. From their names, we can tell they is used for comparing stuff in some. But what exactly was they and what is the difference between them? The following is examples for answering
"Java analog Comparable interface" continuedFirst, the teacher class and the student class comparison size way is not fixed, for example teacher besides compares the title, but also may compare the seniority size, the age size and so on. Then define
Java generic-type erasure I. Overview
Java generics have many problems in use, such as list . class, list cannot be assigned to list (unchangeable), or strange classcastexception. Correct use of Java generics requires a deep understanding of some
Java generic (generics) is a new feature introduced in JDK 5. It allows you to use type parameter when defining classes and interfaces ). The declared type parameter is replaced by a specific type during use. The main application of generics is in
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
Type EraseI. OverviewJava generics in the use of the process has many problems, such as the absence of list.class, list can not be assigned to list (non-covariant), strange classcastexception and so on. Proper use of Java generics requires a deep
Java basics-TreeSet, javatreeset
TreeSet is the implementation class of the SortedSet interface. Sorted is classified in English.
TreeSet ensures that the elements of the set are sorted. Compared with the HashSet set, TreeSet provides the following
# Java Reading Notes # Collection framework 24: Object packaging class of basic data type(1) to facilitate operations on each basic data type, java provides many attributes and methods for us to use.(2) Purpose:The advantage of encapsulating basic
A Buffer object is a container for a fixed number of data. A channel is the entry through which I/O transmissions occur, and buffers are the source or destination of these data transmissions.Buffer baseAll buffers have four properties for
1, basic rules1.0 let your class implements comparable interface, override Method:int CompareTo (Object another)1.1 Ascending obj1 > Obj2 return positiveObj1 = = Obj2 return 0Obj1 1.2 Descending is the opposite of ascending order1.3 If class already
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.