Mega Code Archive

 
Categories / Java Tutorial / Collections
 

The Vectors subList() method does not make a clone of the element references

If you replace the element within the sublist, it is replaced in the original vector. If you remove something from the sublist, it is also removed from the vector. import java.util.List; import java.util.Vector; public class MainClass {   public static void main(String args[]) {     Vector v1 = new Vector();     v1.add("A");     v1.add("B");     v1.add("C");     List l = v1.subList(1, 2);     l.remove(0);     System.out.println(l);     System.out.println(v1);   } } [] [A, C]