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 should I import for arraylist in java?
What is independent and dependent variables in research?
What is multi-catch block in java?
What does sizeof return?
Can a class be private?
Which api is provided by java for operations on set of objects?
Why to use nested classes in java?
What is bufferedwriter?
What is java command?
What is Recursion Function?
give an example for encapsulation?
What is treeset in java?
What is a conditional statement explain with example?
What does next mean in java?
What is arrays fill in java?