This week's giveaway is in the EJB and other Java EE Technologies forum. We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line! See this thread for details.
Output: Enter the Number of Employee:3
Enter the Employee Id:2
Enter the Employee Number:52
Enter the Employee Name:deepak
Enter the Employee Id:4
Enter the Employee Number:62
Enter the Employee Name:Nitin
Enter the Employee Id:1
Enter the Employee Number:12
Enter the Employee Name:anil
Size of Array list:0
Size of Array list:3
The error occurs because you are trying to access an array outside of its bound. For example you define an array that can store 4 elements. But you are trying to access the array using index greater than the size - 1. As we know that array is zero based, the index start from zero to size - 1.
I'm not quite sure what you are asking but if it is the string that is printed out that is the problem, then you need to override the toString method in your Employee class to print out something useful.
Joined: Oct 13, 2005
You are getting Objects out of your List, and they are of type Employee. Read this, which I hope will explain what is happening.
I knew that all things are getting wrong at this place, please suggest me how to get the Object from Array List it should be retrieved by <Employee> type or casting should be done.
I'm not sure what you mean by this as you are getting the Employee object out if the ArrayList and are then calling toString() on it. If your problem is the print out is not printing details of the Employee it's because your Employee class doesn't override the toString() method and return a suitable string containing the details you want to output.
Edit: Beaten by 2 people this time, my typing must be getting slower.
Joined: Aug 30, 2012
Ok, Overriding toString() method will solve my problem. Can anyone give me a sample example for it. How should i built this method just provide me start...
Joined: Aug 05, 2005
Deepak Naithani wrote:How should i built this method just provide me start...