Java by API/java.util/NavigableMap

Материал из Java эксперт
Версия от 14:11, 31 мая 2010; Admin (обсуждение | вклад) (1 версия)
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к: навигация, поиск

NavigableMap: ceilingKey(T key)

 
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("Key ceiling after Sunday: %s%n", nav.ceilingKey("Sunday"));
  }
}





NavigableMap: floorKey(T key)

 

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("Key floor before Sunday: %s%n", nav.floorKey("Sunday"));
  }
}





NavigableMap: higherKey(String key)

 

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("Key higher after Sunday: %s%n", nav.higherKey("Sunday"));
  }
}





NavigableMap: lastEntry()

 

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());
  }
}





NavigableMap: lowerKey(T key)

 
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("Key lower before Sunday: %s%n", nav.lowerKey("Sunday"));
  }
}





NavigableMap: navigableKeySet()

 
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("Map before Sunday: %s%n", nav.navigableKeySet());
  }
}





NavigableMap: pollFirstEntry()

 

import java.util.NavigableMap;
import java.util.TreeMap;
import java.util.Map.Entry;
public class Main {
  public static void main(String[] args) {
    NavigableMap<Integer, String> map = new TreeMap<Integer, String>();
    map.put(2, "two");
    map.put(1, "one");
    map.put(3, "three");
    System.out.println("Original map: " + map + "\n");
    Entry firstEntry = map.pollFirstEntry();
    System.out.println("First entry: " + firstEntry);
    System.out.println("After polling the first entry: " + map + "\n");
    Entry lastEntry = map.pollLastEntry();
    System.out.println("Last entry:" + lastEntry);
    System.out.println("After polling last entry:" + map);
  }
}





NavigableMap: pollLastEntry()

 

import java.util.NavigableMap;
import java.util.TreeMap;
import java.util.Map.Entry;
public class Main {
  public static void main(String[] args) {
    NavigableMap<Integer, String> map = new TreeMap<Integer, String>();
    map.put(2, "two");
    map.put(1, "one");
    map.put(3, "three");
    System.out.println("Original map: " + map + "\n");
    Entry firstEntry = map.pollFirstEntry();
    System.out.println("First entry: " + firstEntry);
    System.out.println("After polling the first entry: " + map + "\n");
    Entry lastEntry = map.pollLastEntry();
    System.out.println("Last entry:" + lastEntry);
    System.out.println("After polling last entry:" + map);
  }
}