Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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


Please Help Members By Posting Answers For Below Questions

What are the parts of methodology?

960


What does snprintf return?

984


What is an object in java and how is it created?

1037


What is Gang of four design patterns

1043


what is recursion in java

1148


How many types of flags are there?

1006


What happens when a thread cannot acquire a lock on an object in java programming?

993


What is parsing a sentence?

1064


Which list does not allow duplicates in java?

914


What is covariant return type?

1108


What is boolean strategy?

1120


What are local variables?

1030


How to perform selection sort in java?

978


If a class is declared without any access modifiers, where may the class be accessed in java programming?

1196


how to split string in java?

1196