Comparable and Comparator

Source: Internet
Author: User
Tags comparable
comparable&   Comparator are    used to implement sorting in the collection, just comparable the sort that is implemented within the collection, Comparator is the sort that is implemented outside the collection, so, if you want to implement the sort, A method to define the comparator interface outside the collection compare () or to implement the comparable interface within the collection CompareTo (). 

comparable is an interface that the object itself already supports for the comparison to be implemented (such as String    Integer can complete the comparison of the size of the operation)   
    
   and Comparator is a dedicated comparator, when the object does not support the comparison or the self comparison function does not meet your requirements, you can write a comparer to complete the size of the comparison between the two objects.

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.