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 is passing value java?
When should you use arraylist and when should you use linkedlist?
What is the difference between conversation & casting?
In java, what is the difference between method overloading and method overriding?
String class is defined under which package in java?
What are the restriction imposed on a static method or a static block of code?
Which is bigger double or float?
What is java autoboxing?
Can we define constructor in inner class?
What is a singleton puppy?
What is the use of arraylist class in java?
How do you check if a character in a string is a digit or letter?
What is diamond operator in java?
Explain about serializable interface in java?
What are internal and external variables?