zoukankan      html  css  js  c++  java
  • List和数组汉字简单排序(转)

    一、List排序

    Collections.sort()和Collections.reverse()方法提供升序和降序操作。

    public static void main(String[] args) { 
            List<String> list = new ArrayList<String>();
            list.add("刘媛媛");
            list.add("王硕");
            list.add("李明");
            list.add("刘迪");
            list.add("刘布");
            
            //升序   注意:是根据的汉字的拼音的字母排序的,而不是根据汉字一般的排序方法
            Collections.sort(list, Collator.getInstance(Locale.CHINA));
            for (String string : list) {
                System.out.print(string);
            }
            System.out.println();
            //降序
            Collections.reverse(list);
            for (String string : list) {
                System.out.print(string);
            }
     }

    二、数组

    public static void main(String[] args) {
            String[] names = {"王林",  "杨宝", "李镇", "刘迪", "刘波"};  
            // 升序    按汉语拼音字母排序
            Arrays.sort(names, Collator.getInstance(Locale.SIMPLIFIED_CHINESE));
            System.out.println(Arrays.toString(names));   
    }
  • 相关阅读:
    Yantai
    Star War
    douban's woshang
    cannot change font's type in coreldraw
    LuXun said
    WaiTan
    free ubuntu disk前天就收到了寄来的光盘
    Winter Swimming
    before buy laptop买本本前,先来看看
    ubuntu beginer
  • 原文地址:https://www.cnblogs.com/xieegai/p/8298476.html
Copyright © 2011-2022 走看看