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