Java arrays class for array sorting

Source: Internet
Author: User

1. Sorting arrays of basic data types

Note: (1) the sort () in the arrays class uses the " fast sorting method after tuning";

(2) An array of base data types such as int[],double[],char[], thearrays class simply provides the default ascending order, and does not provide a corresponding descending arrangement method .

(3) To sort the arrays of the underlying type in descending order, these arrays need to be converted into corresponding encapsulated class arrays, such as integer[],double[],character[], to sort the arrays of these classes. (In fact, it is better to sort the ascending order first, oneself in the order).

Sort the array in the default ascending order

Two ways to sort descending:

public static void Main (string[] args) {//method one: int arr[]={1,6,3,4};//Default ascending Arrays.sort (arr); for (int i=arr.length-1;i> =0;i--) {System.out.println (arr[i]);} Method Two: Applied to the object type or wrapper type, the base type is using comparable//Integer arr[]={1,6,3,4};//arrays.sort (arr, new Comparator () {//@Override// public int Compare (object O1, Object O2) {//return (integer) o2-(integer) o1;//}//});//for (int i=0;i<arr.length;i++) { System.out.println (Arr[i]);//}//}


Https://www.cnblogs.com/xudong-bupt/p/3168618.html

Java arrays class for array sorting

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.