Sorting API analysis in Java collections __java

Source: Internet
Author: User

Static sort APIs in the 1,arrays class

The sort in Arrays.sort (int[] a) is a quick sort, with a time complexity of O (NLOGN)


Arrays.sort (t[],comparator< super t> C) uses a merge sort, and the merge sort is stable , arranged in natural order when C=null


2,collections static sort api,collections are stable.

Collections.sort (list<t> List), and Collections.sort (list<t> list,comparator<. Super t> C); Using the sort is stable, mainly on the list sort , do not know what sort of method, the source can not see





3,arraylist Sorting API

LIst.sort (comparator< super t> c); Sort list, when c=null, arrange by natural order



sum up a convenient memory:

1, for list sorting, you can use the list's own sort method, or you can use the collections static sorting method, and the collections sorting method is stable

2,arrays Static Sort, one is a fast row, a merge sort (stable)



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.