This week's book giveaways are in the iOS and Features new in Java 8 forums.
We're giving away four copies each of Barcodes with iOS: Bringing together the digital and physical worlds and Core Java for the Impatient and have the authors on-line!
See this thread and this one for details.
The moose likes Beginning Java and the fly likes vector? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Barcodes with iOS this week in the iOS forum
or Core Java for the Impatient in the Java 8 forum!

JavaRanch » Java Forums » Java » Beginning Java
Bookmark "vector?" Watch "vector?" New topic


Suka Hati
Ranch Hand

Joined: Oct 28, 2004
Posts: 56
can anybody explain to me what is Vector in java?does the function is the same with array???
marc weber

Joined: Aug 31, 2004
Posts: 11343

"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
John Dell'Oso
Ranch Hand

Joined: Apr 08, 2004
Posts: 130

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.

I agree. Here's the link:
subject: vector?