Java Learning Diary Collection

Source: Internet
Author: User

First, interface map<k,v>
1.V put (K key, V value)
2.int size ()
3.public class Hashmap<k, v> implements Map<k, v>
The hash value of the key is stored, when put, the key will be replaced, a key value can only correspond to one value
Traversal of 4.Map
Map does not have iterators, traversing through keyset () and values ()
Set<k> KeySet ()
Collection<v> VALUES ()
5.set<map.entry<k,v>> EntrySet ()
public static Interface Map.entry<k,v>
6.V get (Object key)
7.LinkedHashMap
TreeMap

Second, generic type
1.instanceOf
o instanceof Student
Determine if object o belongs to the student class
2. Generics can only add class types and cannot add basic data types, but basic data types will automatically box-and-unboxing
3. A class can have more than one generic
Map<string, student>
List<list<student>>
Map<string,list<student>>

Third, sort
1.comparable<t> interface
A class can define a comparison method for the class by implements the interface and implementing its int compareTo (T o) method, returning an int value
PS: This sort of implementation of sorting method and class binding, rather than comparator flexible
2. Interface comparator<t>
int compare (t O1, T O2)
Define a class, implements the comparator interface, implement the Compare method, pass the object of this class to the sort method (such as Collections.sort or Arrays.sort), implement a custom collation, complete the sort of list, etc.

Iv. Collections
1. Java.util.Collections
The 2.Collections class contains a number of static methods that implement multiple operations on the collection
3.static <t extends Object & comparable<? Super t>> T Max (collection<? extends t> Coll)
Returns the maximum element of the given collection, according to the natural ordering of its elements.

V. Collection-related
1. Set-to-go array
ToArray method in Collection interface <T> t[] ToArray (t[] a)
The method is implemented in a specific collection, and the collection can be converted directly to an array
2. Array to set
There is no ready way to write yourself
3. Enhanced for Traversal collection
The collection can be traversed using the For-each loop

Java Learning Diary Collection

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.