Java Japanese (Kanji) Sort

I wasn't in charge of it, but in the past I had a problem because I couldn't reproduce the special platform-dependent sorting in the program porting project (COBOL-> Java).

If you look up the sorting of characters by the remnants of that time I read an interesting article when I was looking around the sort of Collection.

I tried to find out why Chinese numerals are not sorted in numerical order --give IT a try

Java or a normal system doesn't seem to provide sorting of Chinese numerals.

Sorting


String[] KanjiNumbers = {"one","two","three","four","Five","Six","Seven","Eight","Nine"};
List<String> stringList = Arrays.asList(KanjiNumbers);
		
Collections.sort(stringList);//sort
System.out.println(stringList);//display

result


[one,Seven,three,Nine,two,Five,Eight,Six,four]

If you use Collections # sort (), it will be lined up with 1,7,3 ... As a result of investigation, it seems that it is arranged in Unicode order by default

Numbers UTF16
one feff4e00
Seven feff4e03
three feff4e09
Nine feff4e5d
two feff4e8c
Five feff4e94
Eight feff516b
Six feff516d
Ten feff5341
four feff56db

Try using a class called the Collator class that can prepare a Comparator for each locale. Collator (Java Platform SE 8 ) When I prepared a sort for Japanese here, the kanji became the reading order.

Sort by Japanese locale


Collator collator = Collator.getInstance(Locale.JAPAN);
Collections.sort(stringList,collator);
System.out.println(stringList);

result


[one,Nine,Five,three,four,Seven,two,Eight,Six]

I'm not sure, but I think they are lined up according to this rule [Japanese character string collation](https://ja.wikipedia.org/wiki/%E6%97%A5%E6%9C%AC%E8%AA%9E%E6%96%87%E5%AD% 97% E5% 88% 97% E7% 85% A7% E5% 90% 88% E9% A0% 86% E7% 95% AA)

Numbers Read aloud
one Ichi
Nine Kyu
Five Go
three Mr.
four Shi
Seven Seven
two To
Eight That guy?
Six 6

According to the opening article, shift_jis are arranged in this order.

Relation

Only Japanese has different Excel sort and Java sort order A story that seems to have struggled. http://stackoverflow.com/questions/20612110/sort-japanese-data-in-java

It seems difficult to reproduce Japanese sort on another platform

Books etc.

Books often cited during the search (personal notes)

Introduction to character code technology for programmers Java International Programming

Recommended Posts

Java Japanese (Kanji) Sort
java bubble sort
java selection sort
java insertion sort
[java] sort in list
Java Quickstart Japanese translation
[Neta] Sleep Sort in Java
Sort strings functionally with java
Java List Group, Sort, etc.
Bubble sort using ArrayList (JAVA)
[Java, stream] Sort object list in Japanese by property name
Sort a List of Java objects
Java
Java
[Java] Write a sort faster than Arrays.sort
Sort by multiple conditions using Java Stream
Implemented basic search / sort algorithm in Java