Click here to Skip to main content
11,573,666 members (54,383 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: Java list Link
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
Edited 6-Apr-12 4:04am
Mehdi Gholam280.6K
Loke.mysore at 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 at 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 at 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

Advertise | Privacy | Mobile
Web04 | 2.8.150624.2 | Last Updated 7 Apr 2012
Copyright © CodeProject, 1999-2015
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