11:42 pm - Saturday August 18, 2018

Vector Example Program for removeElement(Object obj)

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
@description: removeElement(Object obj) is used to Removes the first (lowest-indexed) occurrence of the argument from this vector.if the elements is removed means return true otherwise return false
 */
import java.util.*;

public class DeeVectorRemoveElements {
	public static void main(String[] args) {
		Vector v = new Vector();// create the vector
		v.add('1');// add the elements
		v.add('2'); // add the elements
		v.add('3'); // add the elements
		v.add('4'); // add the elements
		v.add('5'); // add the elements
		System.out.println("number list: " + v);// to print the elements
		System.out.println("vector size is: " + v.size());// to print the size
								// of the vector
		boolean b = v.removeElement('3');// the element is removed from given
		// vector. The element is removed means return true otherwise return false

		System.out.println("remove elements is present: " + b);// The element is
		//removed means print true otherwise print false
		System.out.println("number list: " + v);// print the elements
		System.out.println("vector size is: " + v.size());// to print the size
								// of vector
		boolean b1 = v.removeElement('7'); // the element is removed from given
		// vector. The element is removed means return true otherwise return false
		System.out.println("remove elements is present: " + b1);// The element
		// is removed means print true otherwise print false

		System.out.println("number list: " + v); // print the elements
		System.out.println("vector size is: " + v.size());// to print the size
															// of vector
	}
}

output
number list: [1, 2, 3, 4, 5]
vector size is: 5
remove elements is present: true
number list: [1, 2, 4, 5]
vector size is: 4
remove elements is present: false
number list: [1, 2, 4, 5]
vector size is: 4

Filed in: Z-A All Java Codes

Comments are closed.