public
synchronized boolean isEmpty()
Returns
true if the vector has no elements else false.
import java.util.*; class VectorIsEmpty{ public static void main(String args[]){ Vector<Integer> myVector; myVector = new Vector<> (); System.out.println("Elements in myVector"); System.out.println(myVector); System.out.print("Is myVector empty "); System.out.println(myVector.isEmpty()); /*Add Elements to myVector*/ myVector.add(10); myVector.add(11); myVector.add(12); myVector.add(10); myVector.add(12); System.out.println("\nElements in myVector"); System.out.println(myVector); System.out.print("Is myVector empty "); System.out.println(myVector.isEmpty()); } }
Output
Elements in myVector [] Is myVector empty true Elements in myVector [10, 11, 12, 10, 12] Is myVector empty false
No comments:
Post a Comment