-2

Should I use ArrayList, Vectors, HashMp or is there anything else I should use to store data from a bank program I am working on. I am trying to store the user information in an one of them and then send it to a file, which should I use? Thank you.

adoba yua
  • 41
  • 7

1 Answers1

1

To decide between using an ArrayList/Vector or a HashMap depends on whether you have key-value pairs or simple a list of elements. For key-value pairs a HashMap is the go-to option (e.g name - person object). If you just have objects but no real keys (a list of trees in a forest) then a ArrayList or Vector would be better.

The difference between Vector and ArrayList is more subtle. If you want more information on the difference between the two you can read this article. But as the article is from 2001, the information isn't the newest.

In most cases, the ArrayList is the better choice and Vector is pretty much considered deprecated nowadays. As the biggest difference between the two is, that Vector is synchronized while ArrayList isn't, which in most cases, makes the Vector slower than the ArrayList as it creates unnecessary overhead. For more information you can look at this question: Why is Java Vector class considered obsolete or deprecated?

Community
  • 1
  • 1
Leon
  • 2,926
  • 1
  • 25
  • 34