Monday, 17 October 2016

java.util.Vector class

java.util.Vector class

java.util.Vector class
  • We can store group of objects in Vector object.
  • Here group of objects means, it can allow us to store same type of objects and different type of objects.
    • Same type means, assuming that all objects are in the form of integer types.
    • Different type means, assuming that all objects are in the form of integer, float, String, Student and Customer types also.
  • Its a legacy class means introduced in 1.0 version.
  • Size will increase dynamically.
  • Vector is synchronized.
  • At a time only one thread is allowed to access the resource, because of synchronization its performance is very slow.
  • Threads need to wait in to access the resource.
--------------------------------------------------------------------------------------------
Program         :       Example on Vector class
Program name  :       VDemo1.java
Output            :         
      [1, Nireekshan, Nireekshan, A, 1.1, 1.12345]
     
import java.util.Vector;

class VDemo1
{
       public static void main(String args[])
       {
             Vector vector = new Vector();
              
             vector.add(1);
             vector.add("Nireekshan");
             vector.add("Nireekshan");
             vector.add('A');
             vector.add(1.1f);
             vector.add(1.12345);
             
             System.out.println(vector);
       }
}
Compile       :         javac VDemo1.java
Run             :         java VDemo1
Output        :         
     [1, Nireekshan, Nireekshan, A, 1.1, 1.12345]
--------------------------------------------------------------------------------------------
Thanks for your time.
Nireekshan