public
synchronized boolean add(E e)
Appends
the specified element to the end of this Vector. Returns true after
adding the Element.
import java.util.*; class VectorAdd{ public static void main(String args[]){ Vector<Integer> myVector = new Vector<> (); /* Add Elements to myColl */ for(int i=1; i < 5; i++){ myVector.add(i); System.out.println("Elements in myVector are"); System.out.println(myVector); } } }
Output
Elements in myVector are [1] Elements in myVector are [1, 2] Elements in myVector are [1, 2, 3] Elements in myVector are [1, 2, 3, 4]
No comments:
Post a Comment