[debutant] tailmap() de SortedMap
(re)bonjour,
je voudrais afficher une liste de noms dont tous les noms st supérieurs (ds l'ordre alphabétique) au nom passé en parametre.
j'ai une TreeMap. les clés sont des noms. je veux afficher seulement une partie de ces noms selon la clé passée en parametre. il existe la methode tailMap() de l'interface SortedMap.
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
tailMap
SortedMap<K,V> tailMap(K fromKey)
Returns a view of the portion of this sorted map whose keys are greater than or equal to fromKey. The returned sorted map is backed by this sorted map, so changes in the returned sorted map are reflected in this sorted map, and vice-versa. The returned map supports all optional map operations that this sorted map supports.
The map returned by this method will throw an IllegalArgumentException if the user attempts to insert a key outside the specified range.
Note: this method always returns a view that contains its (low) endpoint. If you need a view that does not contain this endpoint, and the element type allows for calculation of the successor a given value, merely request a tailMap bounded by successor(lowEndpoint). For example, suppose that suppose that m is a map whose keys are strings. The following idiom obtains a view containing all of the key-value mappings in m whose keys are strictly greater than low:
Map tail = m.tailMap(low+"\0");
Parameters:
fromKey - low endpoint (inclusive) of the tailMap.
Returns:
a view of the specified final range of this sorted map.
Throws:
ClassCastException - if fromKey is not compatible with this map's comparator (or, if the map has no comparator, if fromKey does not implement Comparable). Implementations may, but are not required to, throw this exception if fromKey cannot be compared to keys currently in the map.
IllegalArgumentException - if this map is itself a subMap, headMap, or tailMap, and fromKey is not within the specified range of the subMap, headMap, or tailMap.
NullPointerException - if fromKey is null and this sorted map does not tolerate null keys. |
voila comment je l'ai utilisé ds mon code:
Code:
1 2 3 4 5
|
public Set affichage_en_partie(String s){
TreeMap map_partie = map.tailMap(s);
return map_partie.keySet();
} |
a la compilation, j'ai cette erreur:
Code:
1 2 3 4 5
|
ma_classe.java:195: cannot find symbol
symbol : method tailMap(java.lang.Object)
location: interface java.util.Map
TreeMap map_partie = map.tailMap(s); |
j'ai bien mis en haut de ma classe, import java.util.* (et j'ai rajouté import java.util.Map.* mais je sais pas si ça sert à qch.)
merci de votre aide