9:00 am - Thursday February 22, 2018

Vector Example program to remove specified element using remove()

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

class RemoveElementFromVectorByObject {
	public static void main(String[] args) {
		// creating Vector Object
		Vector v = new Vector();
		v.add("1");
		v.add("2");
		v.add("3");
		v.add("4");
		v.add("5");
		// remove() method is used to remove the specific element from the
		// Vector using Boolean function
		boolean blnElementFound = v.remove("2");
		System.out.println("Was 2 removed from Vector ? " + blnElementFound);
		System.out.println("Vector contents after remove call...");
		for (int index = 0; index < v.size(); index++)
			System.out.println(v.get(index));
		// remove() method is used without using Boolean function
		v.removeElement("3");
		// Boolean object is called to display the rmove elent from vector or
		// not
		System.out.println("Was 3 removed from Vector ? " + blnElementFound);
		System.out.println("Vector contents after removeElement call...");
		for (int index = 0; index < v.size(); index++)
			System.out.println(v.get(index));
	}
}

OUTPUT:

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

Note: RemoveElementFromVectorByObject.java uses unchecked or unsafe operations.

Note: Recompile with -Xlint:unchecked for details.

D:\CandidJava\Util\Vector>java RemoveElementFromVectorByObject

Was 2 removed from Vector ? true

Vector contents after remove call…

1

3

4

5

Was 3 removed from Vector ? true

Vector contents after removeElement call…

1

4

5


BACK

Filed in: Z-A All Java Codes

No comments yet.

Leave a Reply