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 is java virtual machine and how it is considered in context of java’s platform independent feature?
Explain, java is compatible with all servers but not all browsers?
Hi.... I applied for the post of scientific officer/Engineer-SB(Programmer).Please post the syllabus and sample papers.
What will be the initial value of an object reference which is defined as an instance variable?
Explain restrictions for using anonymous inner classes?
what is a thread pool in java and why is it used?
Why pass by reference is not possible in java?
What are java annotations?
How do you declare an empty string?
Can I extend singleton class in java?
Distinguish between a predicate and a function?
Explain where variables are created in memory?
What is object english?
How is tree Mirroring implemented?
How do you check whether the list is empty or not in java?