What is backed collection?

It is a two way communication. If you change something in either collection, that is reflected in other.
import java.util.SortedMap;
import java.util.TreeMap;


public class demo1{
public static void main(String[] args){
TreeMap<String, String> tm = new TreeMap<String, String>();
SortedMap<String, String> sm;
sm = tm.subMap("d","h");
tm.put("a", "ant");
tm.put("d", "dog");
tm.put("h", "horse");
System.out.println(sm);
tm.put("e","eeee");
//sm = tm.subMap("d","h");
System.out.println(sm);
sm.put("g", "xxx");
System.out.println(tm);
}
}
For TreeSet and SortedSet will give the same result.
The same happens with the methods
headSet()
headMap()
tailSet()
tailMap()
 

No comments:

Post a Comment