Collator is used to simplify our processing of differences between different languages. Collator mainly deals:
Normalized typical equivalent characters
Multi-level comparison
Compare Java strings by comparing the Unicode byte code point. This will mean that in UnicodeCodeThe sorting weight specified by the chart character position, but this is no
Author: gnuhpcSource: http://www.cnblogs.com/gnuhpc/
// This comparator uses a collator to determine the // proper, case-insensitive lexicographical ordering // of two strings. class ignorecasecomp implements comparator
Author: gnuhpc
Source: http://www.cnblogs.com/gnuhpc/
// Relationship between the two: 1. The internal implementation of coollections. sort is implemented using arrays. sort.
// 2. If the objects in the list to be sorted have implemented the comparable interface, you can use arrays. Sort To sort objects.
// 3. If the objects in the list to be sorted do not implement the comparable interface, use collections. sort to sort the objects and implement an instance of the comparator interface by yourself. Collections. Sort has two refactoring methods.Impo
list.What if the language is different? The Java. Text package provides the collector and collectionkey classes to sort languages. Here is an example:NOTE: If your text is in the local language rather than the default language, you need to pass a local language to the getinstance () method, just like:
Public static class collatorcomparatorImplements comparator {Collator =
The Java rules described in this article are divided into 3 main levels, this article abandoned the peacetime development of the situation rarely encountered, those who use less later in the high-level chapter appears. And there are six useful international software development issues that are important to note about string, following these rules can improve the efficiency of the program, make the code more readable, and so on.
(1) If a JDBC connectio
Java tutorial translation Sequence Java Introduction Build a JSE development environment-install JDK and eclipse Language basics Java Hello World Program Analysis Variable Java Variables Java Native type Conversion of Java
? It's very messy! We know that the default sorting of the Arrays tool class is compared by the compareTo method of the array elements. Let's look at the main implementation of the String class compareTo:
1 public int compareTo(String anotherString) { 2 int len1 = value.length; 3 int len2 = anotherString.value.length; 4 int lim = Math.min(len1, len2); 5 char v1[] = value; 6 char v2[] = anotherString.value; 7 8 int k = 0; 9 while (k
The
. This method compares two objects based on a certain policy and returns an integer. The interface is defined as follows: The code is as follows:Copy code Int compare (T o1, T o2 ); If o1 is less than o2,-1 is returned; if o1 is equal to o2, 0 is returned; if o1 is greater than o2, 1 is returned.Based on this principle, we implement the following Comparator interface code: The code is as follows:Copy code Package com. guoweiwei. test. comparator;Import
1. String Array sorting:
String [] reallist =...
// Sort by alphabetAlphabetcompare AC = new alphabetcompare ();Arrays. Sort (reallist, AC );
Public class alphabetcompare implements comparator
@ OverridePublic int compare (string str1, string str2 ){Return str1.compareto (str2 );}}
Very simple !!
2. In order to sort the obtained names in alphabetical order, write the following class:
JavaCode
PublicClassAlphabetcomparatorImplementsComparator
PrivateRulebasedcollator
Note: most of the text in this article comes from www.javatang.com. Author: jet MAHArticle: http://www.javatang.com/archives/2007/03/05/5722110.html
The so-called Chinese sorting means sorting by Chinese pinyin, which is not required in Java.Write algorithms by yourself. The sort method provided in the Java. util. arrays class can directly implement this function.Example:Package mypck;Import java. Text.
Import java. Text. collator;
Import java. util. arrays;
Import java. util. comparator;
/*** @ Author Leon* Chinese sorting is performed in the order of Chinese pinyin,* You do not need to write algorithms to sort data in Java,* The sort method provided in the
String comparisons in Java can generally take the compareTo function, and if A.compareto (b) Returns a number less than 0, then the Unicode encoding value of a is less than the Unicode encoded value of B. However, in many cases, we need to develop an app to combine "national conditions", such as in the phone book, we Want "John Doe" in front of "Zhangsan", but if the normal CompareTo function of the string comparison, then "Zhangsan" less than "John D
Import java. text. Collator;Import java. util. Arrays;Import java. util. Comparator;/*** @ Author leon* Chinese sorting is performed in the order of Chinese Pinyin,* You do not need to write algorithms to sort data in Java,* The sort method provided in the
We know that Java's string class has two methods for string comparison: compareto (string) and comparetoingorecase (string ). If you only sort the English strings, this is no problem. However, if you need to sort other languages, the two methods of string are not enough. At this time, we need to use the collator class of the Java. Text package. The collator class
in a comparison class during sorting, because this can also reduce the possibility of null pointers. The passed classes need to be implemented:ComparatorInterface to implement its method: Compare class, although the equals method defined in the interface does not need to worry about it, because the object has been implemented, the equals method is not used in the internal sorting.
The following example is used to sort Chinese characters and objects respectively, and the object is used respecti
In this week's study, lambda expressions, anonymous inner classes, and local inner classes have their own understanding. They are used in callback techniques to reduce the amount of code compared to previous callbacks. This programming task has played a role in reviewing the previous knowledge. Discover the knowledge that you have not mastered before. In a program that sorts names in an identity card, the result is wrong if only arrays.sort () is used to sort the array of strings that consist of
Java. util. Date and Java. SQL. Date, java. SQL. Time, java. SQL. Timestamp interchange, java. SQL. timestamp
1. SQL time type to util time type
Principle: java. SQL. date, java. SQL. t
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.