File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Removing Item From Vector

 
henri henri
Ranch Hand
Posts: 115
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 24204
34
Chrome Eclipse IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
henri henri
Ranch Hand
Posts: 115
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 24204
34
Chrome Eclipse IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 115
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 115
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 29
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 115
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 24204
34
Chrome Eclipse IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


This is exactly what I was describing. Great!
 
Layne Lund
Ranch Hand
Posts: 3061
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic