Click here to Skip to main content
Rate this: bad
good
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 :
     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 6-Apr-12 3:05am
Edited 6-Apr-12 4:04am
Mehdi Gholam236.2K
v2
Comments
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
good
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.
 
—SA
  Permalink  
Comments
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...
--SA

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

  Print Answers RSS
0 OriginalGriff 398
1 Richard Deeming 210
2 Sergey Alexandrovich Kryukov 202
3 PhilLenoir 120
4 RyanDev 115
0 Sergey Alexandrovich Kryukov 6,405
1 OriginalGriff 5,798
2 CPallini 2,473
3 Richard MacCutchan 1,647
4 Abhinav S 1,530


Advertise | Privacy | Mobile
Web03 | 2.8.140821.2 | 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