Java by API/java.util/SortedMap
Версия от 17:43, 31 мая 2010; (обсуждение)
SortedMap: firstKey()
import java.util.Calendar;
import java.util.Locale;
import java.util.Map;
import java.util.NavigableMap;
import java.util.TreeMap;
public class Main {
public static void main(String args[]) {
Calendar now = Calendar.getInstance();
Locale locale = Locale.getDefault();
Map<String, Integer> names = now.getDisplayNames(Calendar.DAY_OF_WEEK, Calendar.LONG, locale);
NavigableMap<String, Integer> nav = new TreeMap<String, Integer>(names);
System.out.printf("Whole list:%n%s%n", nav);
System.out.printf("First key: %s\tFirst entry: %s%n", nav.firstKey(), nav.firstEntry());
}
}
SortedMap: lastKey()
import java.util.Calendar;
import java.util.Locale;
import java.util.Map;
import java.util.NavigableMap;
import java.util.TreeMap;
public class Main {
public static void main(String args[]) {
Calendar now = Calendar.getInstance();
Locale locale = Locale.getDefault();
Map<String, Integer> names = now.getDisplayNames(Calendar.DAY_OF_WEEK, Calendar.LONG, locale);
NavigableMap<String, Integer> nav = new TreeMap<String, Integer>(names);
System.out.printf("Whole list:%n%s%n", nav);
System.out.printf("Last key: %s\tLast entry: %s%n", nav.lastKey(), nav.lastEntry());
}
}