[Java class set] _ sortedmap class notes

Source: Internet
Author: User

[Java class set] _ sortedmap class notes

Objective: To understand the functions of the sortedmap Interface

3. Details
Review: sortedset is the implementation interface of treeset, so this interface can be sorted.
Sortedmap is also a sorting operation. If you have learned the treemap class before, this class can be sorted.

Method for extending the sortedmap interface:
No. method type description
1 Public comparator <? Super K> comparator () Normal Return comparator object
2 Public K firstkey () returns the key of the first element
3 Public soortedmap <K, V> headmap (K Tokey) returns partial sets smaller than or equal to the specified key
4 Public K lastkey () returns the key of the last element
5 Public sortedmap <K, V> submap (K fromkey, K Tokey) returns a set of specified key ranges
6 Public sortedmap <K, V> tailmap (K fromkey) common return part of the set greater than the specified key

Import Java. util. map; import Java. util. sortedmap; import Java. util. treemap; public class sortedmapdemo {public static void main (string ARGs []) {sortedmap <string, string> map = NULL; Map = new treemap <string, string> (); // instantiate the interface object map through subclass. put ("D, jiangker", "www.jiangker.com"); map. put ("C, mldn", "www.mldn.cn"); map. put ("B, mldnjava", "www.mldnjava.cn"); system. out. println (map. firstkey (); system. out. println (map. get (map. firstkey (); system. out. println (map. lastkey (); system. out. println (map. get (map. lastkey (); For (map. entry <string, string> me: map. headmap ("B, mldnjava "). entryset () {system. out. println (Me. getkey () + "-->" + me. getvalue ();} For (map. entry <string, string> me: map. tailmap ("B, mldnjava "). entryset () {system. out. println (Me. getkey () + "-->" + me. getvalue ();} For (map. entry <string, string> me: map. submap ("A, mldn", "C, zhinangtuan "). entryset () {system. out. println (Me. getkey () + "-->" + me. getvalue ());}}}

Output:

B. mldnjava
Www.mldnjava.cn
D. jiangker
Www.jiangker.com
B. mldnjava --> www.mldnjava.cn
C. mldn --> www.mldn.cn
D. jiangker --> www.jiangker.com
B. mldnjava --> www.mldnjava.cn
C. mldn --> www.mldn.cn

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.