2:56 am - Tuesday April 23, 2019

Vector Example program to get Size of Vector using size() through the for loop

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 size() method
 */
import java.util.Vector;

class GetSizeOfVector {
	public static void main(String[] args) {
		// creating Vector Object
		Vector v = new Vector();
		v.add("hai");
		v.add("hai");
		v.add("hai");
		// size() method is used to calculate size of a vector
		int totalElements = v.size();
		System.out.println("Vector contains...");
		// The size of the vector is got through for loop
		for (int index = 0; index < totalElements; index++)
			System.out.println(v.get(index));
	}
}

OUTPUT:

D:\CandidJava\Util\Vector>javac GetSizeOfVector.java

Note: GetSizeOfVector.java uses unchecked or unsafe operations.

Note: Recompile with -Xlint:unchecked for details.

D:\CandidJava\Util\Vector>java GetSizeOfVector

Vector contains…

hai

hai

hai

BACK

Filed in: Z-A All Java Codes

No comments yet.

Leave a Reply