1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
/* Get Size of Java Vector and loop through the elements Example This Java Example shows how to get size or number of elements currently stored in Vector. It also shows how to loop through the element of it. */ import java.util.Vector; public class GetSizeOfVectorExample { public static void main(String[] args) { //create a Vector object Vector v = new Vector(); //Add elements to Vector using v.add("1"); v.add("2"); v.add("3"); //To get size of Java Vector use int size() method int totalElements = v.size(); System.out.println("Vector contains..."); //loop through it for(int index=0; index < totalElements; index++) System.out.println(v.get(index)); } } /* Output would be Vector contains... 1 2 3 */ |
Add Comment