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 is collection sort in java?

775


What is an example of procedure?

753


Is java pass by value or pass by reference?

768


What is a finally block?

780


What is skeleton and stub?

789


I want to print “hello” even before main is executed. How will you acheive that?

914


Tell me about your ability to work under pressure

1968


How many types of flags are there?

751


Can extern variables be initialized?

700


write a program that list all permutations of ABCDEF in which A appears before B?

2255


Is it possible to define a method in java class but provide it’s implementation in the code of another language like c?

836


What is encapsulation in java?

870


what is the purpose of the wait(), notify(), and notifyall() methods? : Java thread

790


How does multithreading take place on a computer with a single cpu in java programming?

768


What about instanceof operator in java?

811