we can use sublist(fromindex,toindex) for get sublist from a vector.
import java.util.List;
import java.util.Vector;
public class GetSubList {
public static void main(String[] args) {
Vector<String> vector = new Vector<String>();
//add element in vector
vector.add("cricket");
vector.add("hockey");
vector.add("football");
vector.add("tennish");
vector.add("java");
// print vector
System.out.println("Vector = "+vector);
/*
* Returns a view of the portion of this
* List between fromIndex, inclusive, and
* toIndex, exclusive. (If fromIndex and toIndex are equal,
* the returned List is empty.) T
*/
List<String> list = vector.subList(1,3);
System.out.println("list is ="+list);
}
}
Output:
Vector = [cricket, hockey, football, tennish, java]
list is =[hockey, football]
import java.util.List;
import java.util.Vector;
public class GetSubList {
public static void main(String[] args) {
Vector<String> vector = new Vector<String>();
//add element in vector
vector.add("cricket");
vector.add("hockey");
vector.add("football");
vector.add("tennish");
vector.add("java");
// print vector
System.out.println("Vector = "+vector);
/*
* Returns a view of the portion of this
* List between fromIndex, inclusive, and
* toIndex, exclusive. (If fromIndex and toIndex are equal,
* the returned List is empty.) T
*/
List<String> list = vector.subList(1,3);
System.out.println("list is ="+list);
}
}
Output:
Vector = [cricket, hockey, football, tennish, java]
list is =[hockey, football]
No comments:
Post a Comment