Click here to Skip to main content
12,550,033 members (46,524 online)
Rate this:
Please Sign up or sign in to vote.
See more: Java
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 :
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 :
Here it will output "0"...
What to do ?? what is wrong with my code ?
Posted 6-Apr-12 3:05am
Updated 6-Apr-12 4:04am
Mehdi Gholam325.5K
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

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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.

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 !!
SAKryukov 12-Apr-12 11:18am
If you still did not get it and need more help, your information is insufficient...

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.161021.1 | Last Updated 7 Apr 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100