This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Instead of Vector? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Instead of Vector?" Watch "Instead of Vector?" New topic
Author

Instead of Vector?

Joe Pluta
Ranch Hand

Joined: Jun 23, 2003
Posts: 1376
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

Joined: Oct 08, 2001
Posts: 2937
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

Joined: Jun 23, 2003
Posts: 1376
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Instead of Vector?