Click here to Skip to main content
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 Gholam240.4K
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
0 Sergey Alexandrovich Kryukov 580
1 ashok rathod 159
2 CPallini 140
3 CHill60 130
4 BillWoodruff 125
0 Sergey Alexandrovich Kryukov 9,543
1 OriginalGriff 6,984
2 CPallini 5,820
3 George Jonsson 4,017
4 Gihan Liyanage 3,266

Advertise | Privacy | Mobile
Web02 | 2.8.140926.1 | Last Updated 7 Apr 2012
Copyright © CodeProject, 1999-2014
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