Click here to Skip to main content
15,846,342 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm Trying to add Objects to a Linked List.
I Have a Class Named "Books".
I add Books Objects to the linked list using the following Code :
<br />
Java
LinkedList<Books> List = new LinkedList<Books>();
List.add(new Books());

But When I Try to get the size of my Linked List , it is always Zero "0" no matter how manny Books I Add.
for example :
Java
System.out.println(List.size());

Here it will output "0"...
What to do ?? what is wrong with my code ?
________________________________________
PLEASE I NEED YOUR HELP ..
Posted
Updated 6-Apr-12 5:04am
v2
Comments
Loke.mysore 6-Apr-12 9:56am    
For the scenario you explained should give the correct answer.
if u din't get means that scenario must be different. check it once again

1 solution

Run it under debugger to make sure that add is actually called, and called before List.size() on the same instance of List. It hardly can be something else.

—SA
 
Share this answer
 
Comments
Shady Hernandez 11-Apr-12 11:53am    
I Did every thing right >> I Called the Linked List as it should be But still when i call the method List.getFirst().getTitle(); it just says no such element exception :S .. I Don't Get it .. What could it be !!
Sergey Alexandrovich Kryukov 12-Apr-12 11:18am    
If you still did not get it and need more help, your information is insufficient...
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900