TreeMapアプリケーション
2218 ワード
public class TreeSort {
public static void main(String[] args) {
CollatorComparator comparator = new CollatorComparator();
TreeMap<String, Object> map = new TreeMap<String, Object>(comparator);
for (int i = 0; i < 10; i++) {
String s = "" + (int) (Math.random() * 1000);
map.put(s, s);
}
map.put("abcd", "abcd");
map.put("Abc", "Abc");
map.put("bbb", "bbb");
map.put("BBBB", "BBBB");
map.put(" ", " ");
map.put(" ", " ");
map.put(" ", " ");
map.put(" ", " ");
map.put(" ", " ");
map.put(" ", " ");
Collection col = map.values();
Iterator it = col.iterator();
while (it.hasNext()) {
System.out.println(it.next());
}
// Set set=map.keySet();
Iterator its = map.entrySet().iterator();
while (its.hasNext()) {
// entry key0=value0
Map.Entry entry = (Map.Entry) its.next();
Object key = entry.getKey();
Object value = entry.getValue();
System.out.println(entry);
// System.out.println(key);
// System.out.println(value);
}
List list = Collections.synchronizedList(new LinkedList());
String s="((2[0-4]\\d|25[0-5]|[01]?\\d\\d?)\\.){3}(2[0-4]\\d|25[0-5]|[01]?\\d\\d?)";
System.out.println("122.068.2.0".matches(s));
}
}
/**
* Java , compare , Comparator ,
* , Collator 。 , :
*
*
*
*/
class CollatorComparator implements Comparator {
Collator collator = Collator.getInstance();
public int compare(Object element1, Object element2) {
CollationKey key1 = collator.getCollationKey(element1.toString());
CollationKey key2 = collator.getCollationKey(element2.toString());
// return -key1.compareTo(key2);
return key1.compareTo(key2);
}
}