• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Instead of Vector?

 
Joe Pluta
Ranch Hand
Posts: 1376
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've been a longtime user of Vectors, but I know that there are better classes available these days. However, I'm not sure what the benefits are of each and how to choose between them.
I have, for example, a need to create something akin to a ResultSet, which contains only a list of field names and then multiple rows of data. It seems to me that it would make sense to have a Vector for the field names and then a Vector or Vectors for the rows. What other options do I have and what are the pros and cons?
Joe
 
John Smith
Ranch Hand
Posts: 2937
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have, for example, a need to create something akin to a ResultSet, which contains only a list of field names and then multiple rows of data. It seems to me that it would make sense to have a Vector for the field names and then a Vector or Vectors for the rows. What other options do I have and what are the pros and cons?
With the new collections framework, there is simply no good reason to use Vectors. Ever. Furthermore, the use of legacy collections, such as Vectors and Hashtables is likely to cause harm to your code. Here is a good explanation by Peter den Haan.
Regarding storing the ResultSet-type data in a collection, you have several options. Most people would probably settle for a List or a Map. The list allows you to access the stored elements by the index, and the Map gives you access by the key.
Collections is an important part of Java, and one should not ignore it. Here is a good Sun's Tutorial on the subject, and Java Collections is probably the best dedicated book on the topic. Once you know what collections framework is all about, there is no way to program in Java without it!
 
Joe Pluta
Ranch Hand
Posts: 1376
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, Eugene! This is exactly what I was looking for. I can store my rows in a List, and use a Map for the field names. And I can say goodbye to my Vectors!
Joe
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic