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...

How does Vector implement synchronization?

Answer Posted / azad bajaj

Almost all the methods in the Vector class are synchronized.
All the methods which either change (read or write) the
values, or change the size or the change the capacity of
the vector.
example method:

public synchronized void setElementAt(E obj, int index) {
if (index >= elementCount) {
throw new ArrayIndexOutOfBoundsException
(index + " >= " + elementCount);
}
elementData[index] = obj;
}

or

public synchronized void removeElementAt(int index) {
modCount++;
if (index >= elementCount) {
throw new ArrayIndexOutOfBoundsException
(index + " >= " +

elementCount);
}
else if (index < 0) {
throw new ArrayIndexOutOfBoundsException
(index);
}
int j = elementCount - index - 1;
if (j > 0) {
System.arraycopy(elementData, index + 1,
elementData, index, j);
}
elementCount--;
elementData[elementCount] = null; /* to let gc
do its work */
}

Is This Answer Correct ?    5 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are the types of arrays in java?

1024


What happens if an exception is throws from an object's destructor?

986


Tell us something about set interface.

957


Write a program to check string is palindrome without using loop?

981


What is a modifier?

1430


What is Java Package and which package is imported by default?

1031


In a container there are 5 components. I want to display the all the components names, how will you do that one?

995


What is unicode datatype?

919


What are the disadvantages of object oriented programming?

1172


What is default size of arraylist in java?

1064


Is space a character in java?

960


What is udp in java?

929


What is java lang object?

924


Explain the difference between the public, private, final, protected, and default modifiers?

984


What is the difference between size and length in java?

927