• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

default size of arraylist

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
what is the default size of arraylist?
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
the default size is 1
 
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
No its not. Try running this:

and see what you get.
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi paul,

yes.you are right.the answare is 1 .but when you add one element to an ArrayList..it will allocate dynamically size 1 right?

please..tell me the default size of vector, hashtable and hashMap
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by seetharaman venkatasamy:
Hi paul,

yes.you are right.the answare is 1



sorry answare is 0(wrongly written)
 
Paul Sturrock
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


but when you add one element to an ArrayList..it will allocate dynamically size 1 right?


It depends on how you add an element. If you use the method add(Object) of the type List the list will be resized. If you use add(int, Object) you will get an IndexOutOfBoundsException.


please..tell me the default size of vector, hashtable and hashMap


You can easily adapt the above program to find this out.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you sure the OP didnt mean "initial capacity"?

If so, this would default to 10, whereas the "default size" would always be 0 unless the - Constructor is used. Then the size would be (obviously) c.size().

Hava look:
http://java.sun.com/j2se/1.5.0/docs/api/java/util/ArrayList.html

Prost
Christoph

[ June 09, 2008: Message edited by: Christoph Naber ]
[ June 09, 2008: Message edited by: Christoph Naber ]
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Paul Sturrock:
It depends on how you add an element. If you use the method add(Object) of the type List the list will be resized. If you use add(int, Object) you will get an IndexOutOfBoundsException.


Only if the index is not 0 (or more formal, if the index is out of range (index < 0 || index > size()))
 
reply
    Bookmark Topic Watch Topic
  • New Topic