Java implementation of Chinese string sorting function instance code _java

Source: Internet
Author: User

No more nonsense, directly to everyone code sharing code.

The specific code looks like this:

 package test;/** * * @Title Information class * @author LR * @version. * @since-*/Public Clas S book {private string book_id; private string book_name; private string publishing_house. Public Book (String book_id, St Ring Book_name, String Publishing_house) {super (); this.book_id = book_id; this.book_name = book_name; this.publishing_ho
Use = Publishing_house;  Public String getbook_id () {return book_id.} public void setbook_id (String book_id) {this.book_id = book_id; String Getbook_name () {return book_name.} public void Setbook_name (string book_name) {this.book_name = Book_name;} pu 
Blic String Getpublishing_house () {return publishing_house.} public void Setpublishing_house (string publishing_house) {
This.publishing_house = Publishing_house; @Override public String toString () {//TODO auto-generated Method Stub return ISBN "+book_id+" \ n title "+book_name+" \ n Publishing House +pub
Lishing_house; }
}

package test;

 import java.text.Collator/** * * @Title Chinese string sorting function * @author LR * @version. * @since
--* * Import java.util.ArrayList;
Import java.util.Collections;
Import Java.util.Comparator; public class Collectionchinesesort implements comparator<book>{collator collator= collator.getinstance (
Java.util.Locale.CHINA); public static void Main (string[] args) {arraylist<book> list=new arraylist<book> (); List.add (new book ("", "
English "," English publishing House "));
List.add (New book ("", "Japanese", "Japanese Press"));
List.add (New book ("", "German", "German publishing House"));
List.add (New book ("", "French", "French Press"));
List.add (New book ("", "Russian", "Russian Publishing House"));
Collections.sort (List,new collectionchinesesort ()); 
for [book Book:list] {System.out.println (book); @Override public int Compare (book book, Book book) {//TODO auto-generated method stub int compare_value=collator.co
Mpare (Book.getbook_name (), Book.getbook_name ());
if (compare_value>) {return;} if (compare_value<) {return-;} return; }
}

The above content is a small series to introduce the Java implementation of the Chinese character string code, I hope to help you!

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.