aspose file tools*
The moose likes Java in General and the fly likes Removing Item From Vector Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Removing Item From Vector" Watch "Removing Item From Vector" New topic
Author

Removing Item From Vector

henri henri
Ranch Hand

Joined: Oct 03, 2005
Posts: 115
I have a Vector full of JavaBeans. Each bean uses the name of a film as a reference. I tried to remove one of my Beans that has 5 occurences due to a erro. I used the contains() method of the Vector class but it doesn't work too well.

Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

If the Vector contains the JavaBeans, then contains() and remove() both want JavaBeans, not Strings, as arguments. If you need to look up the Beans by name, you should consider using a Map (HashMap, say) instead of a Vector.


[Jess in Action][AskingGoodQuestions]
henri henri
Ranch Hand

Joined: Oct 03, 2005
Posts: 115
if I use HashMap I have to put a key and a value. I have film titles, so I don't know what else I sould put as either a key or a value.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

You use the title as the key, and the JavaBean with that title for the value. That's the whole point -- you want to be able to use the key to look up the value.
henri henri
Ranch Hand

Joined: Oct 03, 2005
Posts: 115

The above code give a compiler error. I have no idea what to put as the value, in this case a JavBean. But How?
henri henri
Ranch Hand

Joined: Oct 03, 2005
Posts: 115

This compiles, so I will give it a try. Thanks for your help. I am tryoing to write a program tailored to the needs of a film collector. I am learning the lanaguage at the same time. It is very mind boggling.
Ed Ewing
Greenhorn

Joined: Aug 30, 2005
Posts: 29
Originally posted by henri henri:

The above code give a compiler error. I have no idea what to put as the value, in this case a JavBean. But How?



You need something more like this:
henri henri
Ranch Hand

Joined: Oct 03, 2005
Posts: 115
Thank you very much for your help. I am sure I will get this sorted out in time. It is difficult to concieve of these things when they are mostly invisble. Thanks again.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34



This is exactly what I was describing. Great!
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
For future reference, please post the exact error message you get so that we don't have to guess what the problem is.

Thank you,

Layne


Java API Documentation
The Java Tutorial
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Removing Item From Vector