• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Tim Holloway
  • Carey Brown
  • salvin francis

ArrayList from HeadFirstJava second addition

 
Ranch Hand
Posts: 300
6
  • 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.

 
Saloon Keeper
Posts: 2682
335
Android Eclipse IDE Angular Framework MySQL Database TypeScript Redhat Java Linux
  • 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: 300
6
  • 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!
 
Why should I lose weight? They make bigger overalls. And they sure don't make overalls for tiny ads:
create, convert, edit or print DOC and DOCX in Java
https://products.aspose.com/words/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!