2:20 am - Tuesday April 23, 2019

Vector Example program to remove all elements using clear()

CANDID INDUSTRIAL TRAINING -- CHENNAI
Corporate Training for Experienced Candidate
Struts | Hibernate | Spring | Java / J2EE
SOAP | RestFull | Design Pattern | more...
Ph: +91 72000 69003
137b, 2nd st, shanthi nagar, Chrompet, Chennai -600044
/**
 *@author :CandidJava.com
 *@descriptions : This program explain the function and use of clear() method
 */
import java.util.Vector;

class RemoveAllElementsOfVector {
	public static void main(String[] args) {
		// creating Vector Object
		Vector v = new Vector();
		v.add("1");
		v.add("2");
		v.add("3");
		System.out.println("Size of Vector before removing elements : "
				+ v.size());
		// Clear() method is used to remove all elements from the list
		v.clear();
		System.out.println("Size of Vector after removing elements : "
				+ v.size());
	}
}

OUTPUT:

D:\CandidJava\Util\Vecdtor>javac RemoveAllElementsOfVector2.java

Note: RemoveAllElementsOfVector2.java uses unchecked or unsafe operations.

Note: Recompile with -Xlint:unchecked for details.

D:\CandidJava\Util\Vector>java RemoveAllElementsOfVector2

Size of Vector before removing elements : 3

Size of Vector after removing elements : 0

BACK

/>

Filed in: Z-A All Java Codes

No comments yet.

Leave a Reply