Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

help  RSS feed

 
nash avin
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have an assignment that says the following....

"add or remove objects from the ArrayList variable called "observers"".
Can we add remove objects from variables.?If so how do I go about it.
Any help will be appreciated
nash
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, since this question is in the specific context of the java.util.ArrayList class, you might look at the Javadoc documentation for it. You'll find that this class has, actually, an add() method and a remove() method.
 
nash avin
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply.I will read thro the documentation.
nash
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can we add remove objects from variables?
No. But you can have a variable that refers to an ArrayList object, and you can use that variable reference to invoke mehods on that ArrayList object that would add or remove elements from the ArrayList.
I'm guessing that you're perhaps not quite clear on the role of objects and variables in Java. Let me suggest that you spend a few minutes reading the "Cup Size" and the "Pass-by-Value Please" articles in The JavaRanch Campfire Stories.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!