• 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

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 !
 
My honeysuckle is blooming this year! Now to fertilize this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic