11:15 pm - Sunday February 19, 2017

Remove an element from the Vector E remove(int index)

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

BACK

                                         The remove(int index) method is used to remove the specific element in the vector.It shift upcomeing element  to the left (subtracts one from their indices). Returns the element that was removed from the vector.

Example program

import java.util.Vector;

public class VectorRemove 
{

	public static void main(String[] args)

	{

		Vector h = new Vector(7);

		h.add(5);

		h.add(10);

		h.add(15);

		System.out.println("Numbers:" + h);

		System.out.println("Removed:" + h.remove(0));

		System.out.println("Now numbers are:" + h);

	}
}

Output

   Numbers:[5, 10, 15]

   Removed:5

   Now numbers are:[10, 15]

BACK

Filed in: Java Examples

Comments are closed.