安卓:如何按字母顺序排序的特殊字符的ArrayList? [英] Android : How To Sort An Arraylist of Special Characters Alphabetically?

查看:677
本文介绍了安卓:如何按字母顺序排序的特殊字符的ArrayList?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发一个Android应用程序,我在挪威的语言数据。现在,我必须按字母顺序排序的名字列表,其中姓名包含特殊字符的挪威

I am developing an android application where i have data in Norwegian language. Now , i have to sort a list of name alphabetically where the names contain special norwegian characters.

    Comparator<SetGetMethods> comperator = new Comparator<SetGetMethods>() {

        public int compare(SetGetMethods object1, SetGetMethods object2) {

                return object1.getCityname().compareToIgnoreCase(object2.getCityname());

        }

    };
    Collections.sort(temp, comperator);

我用上面的code按字母顺序排序列表。但排序后,如下图所示它们与普通字符顶部显示的名称和姓名有特殊字符的挪威。例如,该列表中示出像下面,

I used the code above to sort the list alphabetically. But after sorting , the names with normal characters shown on top and names with special norwegian characters shown below them. For example , the list is shown like below ,

亚伦达
卑尔根
德拉门
奥勒松 - >(这应该是在顶部,前亚伦达排序后)

Arendal Bergen Drammen Ålesund -> ( This should be on top , before Arendal after sorting )

所以,我的问题是,在那里按字母顺序列表数据中包含特殊字符(字符挪威),我怎样才能给列表排序。我将AP preciate任何建议,想法或样品code来解决这个问题。谢谢.....

So , my question is , how can i sort a list alphabetically where the list data contains special characters(Norwegian characters). I will appreciate any suggestion , idea or sample code to solve the problem. Thanks .....

推荐答案

看一看在的的JavaDoc为RuleBasedCollat​​or类

在此基础上,我创造了这个例子,把一个基于一个口音区别之前 - 注意使用;把\\ u00E5 A之前因此,这适用于你的例子投入,但你需要添加其他重音挪威字符根据您的语言知识,完成挪威比较字符串。

Based on that, I've created this example that puts Å before A based on a accent difference -- note the use of ';' to put \u00E5 before A. So this works for your example input, but you'll need to add other accented Norwegian characters based on your knowledge of the language to complete the norwegian comparison string.

String norwegian = "< a, \u00E5;A< b,B< c,C< d,D< e,E< f,F< g,G< h,H< i,I< j,J" +
                   "< k,K< l,L< m,M< n,N< o,O< p,P< q,Q< r,R< s,S< t,T" +
                   "< u,U< v,V< w,W< x,X< y,Y< z,Z";                      
RuleBasedCollator myNorwegian = new RuleBasedCollator(norwegian);     
List<String> words = 
  Arrays.asList("Arendal Bergen Drammen \u00E5lesund".split("\\s"));     
System.out.println(words);     
Collections.sort(words, myNorwegian);     
System.out.println(words);

这篇关于安卓:如何按字母顺序排序的特殊字符的ArrayList?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆