This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Collection Objects  RSS feed

 
Harini Mamidi
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are the collection objects immutable? like for example java.util.Vector...?
[ January 09, 2004: Message edited by: Harini Mamidi ]
 
Corey McGlone
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Of course not. Notice that the collection objects have methods such as add and remove. These directly imply that the collections can be changed and, therefore, are not immutable.
Saying that something is immutable means simply that it CAN NOT be changed after it is created. That is certainly not the case with a collection.
 
Harini Mamidi
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank U for the reply
 
Yosi Hendarsjah
Ranch Hand
Posts: 166
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You CAN create immutable collections. The easiest way is by using the class java.util.Collections. There are several static methods (the methods' names start with 'unmodifiable'). The harder way is to create your own class that implements Collection interface or to extend the existing collection classes.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!