which of tha following is not a thread safe class?
a) ArrayList b)Vector c)HashTable d)None
Answer Posted / aravinda reddy
ArrayList is by default not thread safe, but we can make it
thread safe. Below is the example how we can make it thread
safe.
public class SynchronizeList {
public static void main(String[] args) {
ArrayList<String> al=new ArrayList<String>
();
al.add("1");
al.add("2");
al.add("3");
//we can make the synchronized
Collections.synchronizedList(al);
synchronized(al) {
Iterator i = al.iterator(); // Must
be in synchronized block
while (i.hasNext())
System.out.println(i.next());
}
}
}
Vector and HashTable are by default synchronized. These are
thread safe.
Hence the answer is ArrayList.
| Is This Answer Correct ? | 1 Yes | 0 No |
Post New Answer View All Answers
What restrictions are placed on method overloading in java programming?
What is an argument java?
Explain the private field modifier?
What is the program development process?
What is java english?
How can you say java is object oriented?
What is computer compiler?
what is collatration?
Explain creating threads by extending thread class ?
How do you print array in java?
What is string data?
What is the advantage of functional interface in java 8?
What is float in java?
What is application tier?
What is the java virtual machine?