How does Vector implement synchronization?

Answer Posted / swamy

import java.util.Vector;

public class VectorExample {

public static void main(String[] args) {

Vector<String> vc=new Vector<String>();

// <E> Element type of Vector e.g. String, Integer, Object ...

// add vector elements
vc.add("Vector Element 1");
vc.add("Vector Element 2");
vc.add("Vector Element 3");
vc.add("Vector Element 4");
vc.add("Vector Element 5");

// add vector element at index
vc.add(3, "Element at fix position");

// vc.size() inform number of elements in Vector
System.out.println("Vector Size :"+vc.size());

// get elements of Vector
for(int i=0;i<vc.size();i++)
{
System.out.println("Vector Element "+i+" :"+vc.get(i));
}
}
}

Is This Answer Correct ?    1 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What exactly is java?

707


Can we declare an interface as final?

786


What is hotjava?

743


How does the java compiler work?

740


What is immutability in java?

821


Which data type is a class in java?

769


Explain the hierarchy of java exception classes?

803


Is main is a keyword?

791


What do you understand by an io stream?

799


What is a private class in java?

733


What is bitwise complement?

725


Explain constructors and types of constructors in java.

839


What is the difference between checked exception and unchecked exception?

784


What is string pool in java?

767


How do you identify if jvm is 32-bit or 64-bit from java program?

734