I have two classes EmpData and VectorHandler.
EmpData contains info abt employees like name and empcode
Vectorhandler has a vector which stores Empdata objects .
I want to use removeElement() which will delete the object which contains the particular empname/empcode from the vector.
This doesnot work:


as empcode is not of type object but a simple int variable.
How do i delete the particular object which contains that particular empcode

Well you'd have to search through the Vector; once you've found the code, you'd have access to the Object you need to remove and thus v.remove(empData); will work. The easiest way to iterate over the Vector is:

for (EmpData empData: v)
    if (empData.code == empCode)

Here I assume that you declared v as: Vector<EmpData> v = new Vector<EmpData>(); . Since Vector objects are iterable, I was able to use the for loop as seen above where empData refers to a single element in the Vector v. Hope that helps! I also hope you recognize that removeElement() is a method designed to remove an existing Object within the Vector that matches the input of removeElement().

But code is a private variable in my EmpData class.
Heres my code:

//PRogram to demonstrate interaction between a class object and a vector

import java.lang.*;
import java.io.*;
import java.util.*;

 class EmpData { 
	private String name = new String();
	private int code = 0;
	int c = 0;
	BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
	 	System.out.println("Enter empcode : ");
	     code = Integer.parseInt(in.readLine());
	 	}catch(Exception e){}	
	void display(){
		System.out.println("You enterd : " + code);

class VectHandler { 
	   private Vector<EmpData> vect = new Vector<EmpData>();
	   void add_vect(){
	     EmpData d = new EmpData();
	   	 System.out.println("obj added!");
	   void disp_vect(){
	   	for(int i = 0; i<vect.size(); i++){
	   void delete_vect(){
	   	System.out.println("Enter the code to be deleted:");
	   	BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
	   	int empcode = Integer.parseInt(in.readLine());
	   	for (EmpData empData: vect){
	   	    if (empData.code == empcode)        

class test2_ED_vect {
 public static void main(String args[])	{
 	VectHandler v = new VectHandler(); //used to handle implementing vectors from VectorHandler class   

//this code is used for implementing vectors from main   
/* 	Vector v = new Vector();
 	v.addElement(new ED("Hello"));
 	v.addElement(new ED("Mello"));
*/ //this code works fine with no VectorHandler defined/declared 


compiler gives me this error:
--------------------Configuration: JDK version 1.5.0_06 <Default>--------------------
C:\Program Files\JCreator LE\MyProjects\string1\test2_ED_vect.java:48: code has private access in EmpData
if (empData.code == empcode)
1 error

Process completed.

So add a method to the object that will allow you to compare it with another value.