Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

vector?

 
Suka Hati
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can anybody explain to me what is Vector in java?does the function is the same with array???
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
http://java.sun.com/j2se/1.5.0/docs/api/java/util/Vector.html
 
John Dell'Oso
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Suka,

You can view a vector as a "growable" array. That is, the vector grows or shrinks according to how many items your add or remove to or from it. The major difference is that you can only store objects (or object references) in a vector. An array can store primitive data types in addition to object references.

Having said that, you would be well advised to use the ArrayList class in place of a vector. The ArrayList is part of the Java Collections framework and is more efficient. Anything you can do with a vector, you can do with an ArrayList. The difference between the two collections is that Vector is synchronised whereas ArrayList (plus any of the other new collection implementations_ is not. From a beginner's learning point of view, this is not an issue. You can learn more about this when you learn about threads.

As suggested in a previous reply, check out the API documentation for these classes to learn more.

Regards,
JD
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic