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 is passing value java?

1051


When should you use arraylist and when should you use linkedlist?

924


What is the difference between conversation & casting?

1038


In java, what is the difference between method overloading and method overriding?

1113


String class is defined under which package in java?

1069


What are the restriction imposed on a static method or a static block of code?

1053


Which is bigger double or float?

962


What is java autoboxing?

938


Can we define constructor in inner class?

995


What is a singleton puppy?

979


What is the use of arraylist class in java?

1068


How do you check if a character in a string is a digit or letter?

1066


What is diamond operator in java?

941


Explain about serializable interface in java?

992


What are internal and external variables?

951