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
What are annotations in java?
Give differences between Quicksort & Mergesort. When should these sorts be used and what is their running time?
Why is multithreading important?
What is the difference between choice and list?
Can we print null in java?
Do loops java?
What is a Null object?
What do you understand by a Static Variable?
What is the main purpose of serialization in java?
What is the difference between the direct buffer and non-direct buffer in java?
What is Major and importance difference between for and foreach loop ?
Can we execute a program without main() method?
What is the difference between preemptive scheduling and time slicing in java programming?
What is difference between printf and scanf?
How do you escape a string?