JAVA開発メモ

 

[リロード]   [新規|編集|差分|添付]   [トップ|一覧|単語検索|最終更新|バックアップ|ヘルプ]

サイトメニュー

public class Person implements Comparable { private String id; // ID public Person(String id, String name, String nameKana) { this.id = id; this.name = name; this.nameKana = nameKana; } public String getId() { return id; } public String getName() { return name; } public String getNameKana() { return nameKana; } public void setId(String string) { id = string; } public void setName(String string) { name = string; } public void setNameKana(String string) { nameKana = string; } public String toString() { } public int compareTo(Object obj) { return this.id.compareTo(((Person) obj).getId()); } } Person[] array = new Person[5]; for (int i = 0; i < array.length; i++) System.out.println(array[i]); List list = new ArrayList(); Collections.sort(list); for (int i = 0; i < list.size(); i++) System.out.println(list.get(i)); Person[] array = new Person[5]; Comparator asc = new Comparator() { public int compare(Object obj0, Object obj1) { String nameKana0 = ((Person) obj0).getNameKana(); String nameKana1 = ((Person) obj1).getNameKana(); int ret = 0; if ((ret = nameKana0.compareTo(nameKana1)) == 0) { String id0 = ((Person) obj0).getId(); String id1 = ((Person) obj1).getId(); ret = id0.compareTo(id1); } return ret; } }; for (int i = 0; i < array.length; i++) System.out.println(array[i]); Comparator desc = new Comparator() { public int compare(Object obj0, Object obj1) { String nameKana0 = ((Person) obj0).getNameKana(); String nameKana1 = ((Person) obj1).getNameKana(); int ret = 0; if ((ret = nameKana1.compareTo(nameKana0)) == 0) { String id0 = ((Person) obj0).getId(); String id1 = ((Person) obj1).getId(); ret = id1.compareTo(id0); } return ret; } }; for (int i = 0; i < array.length; i++) System.out.println(array[i]);

リロード   新規 編集 差分   トップ 一覧 検索 最終更新 バックアップ   ヘルプ   最終更新のRSS
Last-modified: Tue, 15 Feb 2005 14:08:18 UTC (6300d)
Link: (4985d)

Modified by MT22(Moriwaki Takashi)

"PukiWiki" 1.3.7 Copyright © 2001,2002,2003 PukiWiki Developers Team. License is GNU/GPL.
Based on "PukiWiki" 1.3 by sng
Powered by PHP 7.4.28

HTML convert time to 0.024 sec.