Vector in java

Vector is a member in Collections frame work of Java  .It implements the List interface. It is a legacy class in java.Vector was in Java in the earlier versions itself.

Vector & ArrayList

Vector is almost same as that of ArrayList.Vector also based on index values for each items. But the methods in vector class are thread safe. This gives a little performance  fall.Vector ,like ArrayList  implements the interface RandomAccess  .So the only difference between Vector and ArrayList is the thread safety of its methods.

Now let us see an example code and its output. It adds few string values to the vector .Displaying those values , then removing the strings.

Output

Displaying contents of vector

Item = dog

Item = cat

Item = cow

Item = elephant

Item = sheep

Removing contents of list

Contents removed  ,now size of vector = 0

See Related Discussions

Collections in Java

ArrayList

LinkedList

HashMap

HashSet

Tagged with 

One thought on “Vector in java

  1. […] c)Vector: It is one of the legacy class with Java. Vector is almost similar to ArrayList.The difference is vector methods are thread safe. This causes a performance downfall for Vector when compared with ArrayList. […]

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title="" rel=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">