Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Collection Objects

 
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