Arrays. Sort string is used for sorting by character. case-insensitive characters are ignored.

Source: Internet
Author: User

Sometimes you need to sort the elements in the logarithm group. Of course, you can write a proper sorting method by yourself. But since there is an arrays. Sort sorting method in the Java package, why not use it when there are few array elements?

Sorting an array
 
1. digit sorting
 
Int [] intarray = new int [] {4, 1, 3,-23};
Arrays. Sort (intarray );
Output: [-23, 1, 3, 4]
 
2. Sort strings in upper case and lower case
 
String [] strarray = new string [] {"Z", "A", "C"};
Arrays. Sort (strarray );
Output: [C, A, Z]
3. Strictly sort by alphabet, that is, ignore case-insensitive sort
Arrays. Sort (strarray, String. case_insensitive_order );
Output: [A, C, Z]
 

4. Reverse sorting, reverse-Order sort
Arrays. Sort (strarray, collections. reverseorder ());
Output: [Z, a, c]
 

5. Ignore case-insensitive reverse sorting case-insensitive reverse-Order sort
Arrays. Sort (strarray, String. case_insensitive_order );
Collections. Reverse (arrays. aslist (strarray ));
Output: [Z, C, A]
 
 

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.