Flask接口签名sign原理与实例代码浅析
255
2023-07-19
Java实现对中文字符串的排序功能实例代码
废话不多说了,直接给大家代码分享代码了。
具体代码如下所示:
package test;
/**
*
* @Title 书的信息类
* @author LR
* @version .
* @since --
*/
public class Book {
private String book_id;
private String book_name;
private String publishing_house;
public Book(String book_id, String book_name, String publishing_house) {
super();
this.book_id = book_id;
this.book_name = book_name;
this.publishing_house = publishing_house;
}
public String getBook_id() {
return book_id;
}
public void setBook_id(String book_id) {
this.book_id = book_id;
}
public String getBook_name(http://) {
return book_name;
}
public void setBook_name(String book_name) {
this.book_name = book_name;
}
public 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 "书号"+book_id+"\n书名"+book_name+"\n出版社"+publishing_house;
}
}
package test;
import java.text.Collator;
/**
*
* @Title 中文字符串排序功能
* @author LR
* @version .
* @since --
*/
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
public class CollectionChineseSort implements Comparator
Collator collator= Collator.getInstance(java.util.Locale.CHINA);
public static void main(String[] args) {
ArrayList
list.add(new Book("","英语","英语出版社"));
list.add(new Book("","日语","日语出版社"));
list.add(new Book("","德语","德语出版社"));
list.add(new Book("","法语","法语出版社"));
list.add(new Book("","俄语","俄语出版社"));
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.compare(book.getBook_name(),book.getBook_name());
if(compare_value>){
return ;
}
if(compare_value<){
return -;
}
return ;
}
}
以上内容是给大家介绍的Java实现中文字符串的排序功能的代码,希望对大家有所帮助!
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~