First of all, the two are used for sorting, but the application is a little different.The following scenarios are available:For list List = new arraylist (); We can directly use Collections.sort (list); Sort. So if we have a class like: Person class,
1.TreeSet principle:/** TreeSet can be sorted when storing objects, but it is necessary to specify an algorithm for sorting** Integer can be sorted (with default order), string can be sorted (with default order), the custom class is stored with an
The collection interface is the root of the collection interface tree and defines a common API for collection operations. The function is to facilitate the programmer to handle a set of common elements.Note: object[] ToArray (object[] a): Returns an
Collection frame: ★★★★★, a container for storing data.Characteristics:1: Objects encapsulate data, and objects need to be stored. Collection is used to store objects.2: The number of objects determines the array can be used, but is not sure what to
1.ArrayList and LinkedListThe list interface is a sub-interface of collection, which defines a linear table data structure.The list can be understood as an array of objects, except that the number of elements can be dynamically increased or
The inheritance relationships of common data structure objects in 1.j2se such asCollection........| --------List........| ..........| ----------ArrayList........| ..........| ----------Vector........| ..........| .............| -----Stack........| ..
Analysis of two comparison interfacesThe former should be fixed, bound to a specific class, and the latter more flexible, which can be used for each class that needs to compare functions.A class implements the Camparable interface to indicate that
Take intwritable as an example to introduce the steps to customize the writable//the Writablecomparable interface inherits the writable interface and the comparable interface Public classIntwritableImplementsWritablecomparable {//define member
"Detailed study of Java collections" List,set,map usage and differencesCollection is the most basic set interface, and a collection represents a set of object, the collection element. Some collection allow the same elements while others do not. Some
Questions:1. What is a collection2. What kinds of collections are reused?3. Storage sample of HashSet in set4, the collection of traversal methodsCollection: A collection container that stores object dataSingleton Collection--–| Collection the root
1 1. Collection 2 Collection (Single-column collection)3 List (ordered, repeatable)4ArrayList5 The underlying data structure is an array, query fast, and delete slowly6 thread insecure, high efficiency7 Vector8 The underlying data
Like integer, string These types of data are already implemented comparable interface, so for these types can be directly through the Arrays.sort (...) and Collections.sort (...) method to sort. But for some of your own new objects, if you want to
The set interface does not extend the collection interface, but is more stringent than the collection interface, does not add duplicate elements, and uses a hash of the storage method, so there is no
The Java Collection schema supports 3 types of collections: Rule set (set), Linear table (list), and diagram (map), respectively, defined in Set,list,map.A set instance stores a set of distinct elements (collections), a list instance stores a set of
There are two ways to sort list by using the Collections.sort methodThe first is that the object in the list implements the comparable interface, as follows:[Java]View PlainCopy
/**
* Sort the user according to order
*/
Public class User
Original link: http://blog.csdn.net/veryisjava/article/details/51675036Collections to sort data in a list collectionSometimes it is necessary to sort the elements in the collection according to certain rules, which requiresA tool class collections
Before introducing sorting, let's first describe a few of the methods that need to be used in each sorting algorithm, and I write them separately in a class that is less (), the Exchange (), the Issort () method, the less () method to determine the
Introduction to the Basic java Set (3), javaset
Today, we mainly talk about the summer set. We will take an hour every day to sum up and make life better!
--
Java.
Util> -- Set Interface:
Data Structure: data storage method;
The methods in the Set
Set-TreeSet-Comparable and treeset
Student Class: name and age attributes1 package com. bjpowernode. test01_set2_Comparable; 2/* 3 * T: type 4 */5 public class Student implements Comparable {6 private String name; 7 private int age; 8 public String
Behind the post, we will start Java's Common advanced technology learning.Interface technology, which is mainly used to describe what functions a class has, and does not give a specific implementation of each function. A class can implement
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.