Win a copy of Rust Web Development this week in the Other Languages forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

ArrayList & Vector

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not an advanced question. Moving...
 
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 1274
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ooohhhh
He was talking of "Member # 134857". Sorry i really didn't get that.
Good observation.

Regards
Makarand Parab
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic