• Post Reply Bookmark Topic Watch Topic
  • New Topic

ArrayList from HeadFirstJava second addition  RSS feed

 
Lisa Austin
Ranch Hand
Posts: 178
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I'm using the book HeadFirstJava second edition.  Pg. 133 it teaches about ArrayList.   I am practicing the example codes it provides but the last example confuses me.
The is supposed to have removed an object from the array and now the ArrayList is an array of one instead of two.  When I tried it myself and printed the results it appears to have not worked.
What did I do wrong here or how should it have worked?

Thank you.

 
Ron McLeod
Saloon Keeper
Posts: 1601
232
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It still prints 2 because it still has the value assigned to it in line 20, before you removed any elements.

Also, if you were unsure if the element was removed from the array, check the return value for myList.remove(s).  It will return true if an element was removed, false if not.
 
Lisa Austin
Ranch Hand
Posts: 178
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ron McLeod wrote:It still prints 2 because it still has the value assigned to it in line 20, before you removed any elements.

Also, if you were unsure if the element was removed from the array, check the return value for myList.remove(s).  It will return true if an element was removed, false if not.


Ah I gotcha .  Thank You!
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!