• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to remove object from Vector?  RSS feed

 
Sanam Kumar
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a Vector itemDetails to which an object UsageItem usageitem is added.
itemDetails.add(usageitem);
I want to remove an object from vector (itemDetails) based on the condition that if "key" is already present in the vector, then the particular object should be removed from th vector.

I dont know how to remove this element from the Vector. Please help.

 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not an advanced question. Moving...
 
John Bartlett
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

First of all im presuming key is unique....

How about creating a Map of UsageItem where the key is the UsageItem's key attribute and the value is the object istelf? then you could check the keys and replace or remove the item?

Or a Set, a set does not allow duplicate elements?

Eitehr that or loop through the list of UsageItem's and check each key and then when you come across a duplicate remove it?

Probably different solutions out there tho, hope this helps.

John
[ October 13, 2006: Message edited by: John Bartlett ]
 
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
Please don't post the same question to more than one forum. See here for an explanation of why I just deleted the other copy of this thread.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!