• 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

Vector

 
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hi, all
When compile and run this:
import java.util.*;
public class Q5 {
public static void main (String[] args) {
Q5 obj = new Q5();
Vector vectorDemo = new Vector(10);
Vector vectorDemo1 = new Vector();
System.out.print(vectorDemo.size() + ",");
System.out.print(vectorDemo.capacity() + ",");
System.out.print(vectorDemo1.size() + ",");
System.out.print(vectorDemo1.capacity());
}
}
the capacity of vetordemo1 give 10 ?
10 is the default capacity ? Some comments ?
Thx in adv
 
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ricardo
The initial size of a Vector is 10 (check out the default constructor in the API). Although I can't find the reference, I believe the initial capacity is the same as the size unless you use one of the other constructors to explicitly set the capacity.
someone correct me if I'm wrong

Dave
 
Ranch Hand
Posts: 625
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You've pretty much got it Dave. Just to add, a vector is at least as big as it's capacity and usually bigger. Since you used the constructor Vector(int initialCapacity) The capacity comes up as 10, as Dave pointed out.

- Sean
 
Ricardo Polero
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thx a lot guys !
 
You had your fun. Now it's time to go to jail. Thanks for your help tiny ad.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic