Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ArrayList & Vector

 
Amrita Puja
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi.

Difference between arraylist and vector is that, arraylist is synchronized where as vector is synchronized, in arraylist when the data added increases array size will increase, but in vector when initial size should be specified, if we add more data to it, it will double the size giving more allocations.

According to my knowledge, these are the diffrences i know.

Please tell me these differences are correct or not. If more differences are there, post those answers.

If arraylist is not synchronized, how we can do it synchronized.

If already list is there, what is the need of arraylist.

Thankyou.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not an advanced question. Moving...
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Difference between arraylist and vector is that, arraylist is synchronized where as vector is synchronized
False, ArrayList is unsynchronized.
in arraylist when the data added increases array size will increase, but in vector when initial size should be specified, if we add more data to it, it will double the size giving more allocations.
This depends on how you construct the Vector. Check java.util.Vector #capacityIncrement
If arraylist is not synchronized, how we can do it synchronized.
List<E> synchronizedList = Collections.synchronizedList(new ArrayList<E>());
If already list is there, what is the need of arraylist.
List is an interface, ArrayList is a basic implementation of this interface.
[ October 12, 2006: Message edited by: Bauke Scholtz ]
 
Makarandp Parab
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi As you said, the differences you have given about Arraylist and Vector are perfect. Now about you queries If arraylist is not synchronized, how we can do it synchronized.?

If you want to make arraylist synchronized, you should use Collections.synchronizedCollection(Collection c) method or you can use Collections.synchronizedList(List list) method in the Collections class.

If already list is there, what is the need of arraylist? Amrita, check the API[java.util]. List is an interface which sets the rule where as Arraylist implements the List interface.

Regards Makarand
 
Burkhard Hassel
Ranch Hand
Posts: 1274
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ranchers,


Vector came first. It was already introduced into Java in version v1.2.
Due to this, Vector still has the old method names like addElement. This method identifier (and the like) is/are not found in ArrayList.


Yours,
Bu.


p.m., hey, Makarandp, do you know, your member number is a prime?
 
Makarandp Parab
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Burkhard Hassel
"hey, Makarandp, do you know, your member number is a prime?" - i didn't get what you want to say. Can you come back please.

Regards
Makarand parab
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A prime number is divideable to a round number by 1 or itself only. Your member number 134857 is such one.
Also see http://en.wikipedia.org/wiki/Prime_number

Nothing to do with yourself
[ October 12, 2006: Message edited by: Bauke Scholtz ]
 
Makarandp Parab
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ooohhhh
He was talking of "Member # 134857". Sorry i really didn't get that.
Good observation.

Regards
Makarand Parab
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic