Initial alphabetical order in Java Kanji

Source: Internet
Author: User
Tags collator locale

Recently, Bo Master to do the project needs to do a WAP version of the mobile phone address Book, the afternoon to organize the next idea, found that the user name how to sort ah? Product manager said to make and mobile phone directory similar to the line (heart 10,000 god Beast floated), well, since the proposed to do something, as a programmer should be indomitable!!

First Bo main thought is to solve this problem from the front end, so simply looking for information, see if there is no ready code, find a small meeting, did not find anything good JS can handle this matter, hey ... Bo main front-end slag Ah, well, turn to the background to deal with, the front-end you are waiting to concentrate on the display of data it!

Check the relevant API found comparator this interface unexpectedly has this function, really saved a good part of the time, the following paste code:

package demo;import java.text.collator;import  Java.util.arrays;import java.util.comparator;public class test { public static  void main (String[] args)  {  // Collator  class is used to perform a locale-sensitive  string   comparison, here is the option to use China  comparator comparator = collator.getinstance ( Java.util.Locale.CHINA);  string[] arrstrings = {  "AA", "AA", "11", "Side dish", "Mirror flower 8 Water Month 90",   "www.noreplace.com",  "flower is not right",  "mirror flower 7 Water Month 90", "little silly"  };  //  causes the specified array of objects to be sorted according to the order produced by the specified comparer.   arrays.sort (Arrstrings, comparator);  for  (int i = 0; i  < arrstrings.length; i++)    system.out.println (ArrStrings[i]);  }} 

The above first define the comparator, using the Chinese character comparator, and then directly call the method is OK, is not very convenient? Haha, huh!

Operation Result:

11aaaawww.noreplace.com Flower No Mirror flower 7 water Month 90 mirror flower 8 water Month 90 small dish silly

Here is the use of ASCII code comparison, we are interested to know the next ...

For more information please follow my personal blog: The illusion of the blog reprint please bring the source link, thank you, www.noreplace.com

This article is from the "11437810" blog, please be sure to keep this source http://11447810.blog.51cto.com/11437810/1762939

Alphabetical order in Java Kanji

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.