JAva中国語ソートまたは中国語オブジェクトを含むソート

886 ワード


public class SamContact  implements Comparable<SamContact>
	{
		public String name = "";
		public String phone = "";
		public boolean isChoosed = false;

		@Override
		public String toString() {
			return name;
		}

		public int compareTo(SamContact another) {
			try {
				RuleBasedCollator ruleBasedCollator = (RuleBasedCollator)Collator.getInstance(Locale.CHINA);
				return ruleBasedCollator.compare(name, another.name);
				
			} catch (Exception e) {
				e.printStackTrace();
				return this.name.compareTo(another.name);
			}

		}

		

	}
ArrayList<SamContact> list = new ArrayList<SamContact>();
list.add(**);
....
Collections.sort(list);