• 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
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

finding vector's size

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a vector with predefined size 4.
And now i would like to know how many objects are present in that vector??
When i am trying vector.size() in for loop its giving the error because of its predefined size.
Any one can help...
Thank you
 
Ranch Hand
Posts: 326
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you want to iterate through the members of a Vector, use the Enumeration you get from Vector.elements()
 
naidu rasagna
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But i dont want to iterate. i just want to know the original size and i have to compare it with another variable....
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"rasagna" who was formerly "j@smin j@smin" - well, I suppose you're getting closer. But the new name doesn't work either. We need a first and last name. That implies a minimum of two. Thank you.
 
Sheriff
Posts: 26770
82
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by rasagna:
When i am trying vector.size() in for loop its giving the error because of its predefined size.

Well, next time it does that, have a look at the error message. The words in an error message are usually designed so that they describe the problem that is happening, and that is most likely the case with the error message you are getting there. If you don't understand the message, then post it here.
 
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are using the term "predefined size" which is not defined for Vector. Why not post a short example program demonstrating your problem. 5 or 10 lines should suffice.
 
Ranch Hand
Posts: 1078
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would venture a guess that you are mistaking a Vector's size for it's capacity. I'm guessing you are creating it using new Vector(4) which returns a Vector with an initial capacity of 4. It's size is 0 until something is added. size() will tell you how many objects are present in the Vector and it has nothing to do with the initial capacity you set it to.

Edit: Oops I meant size() not getSize(). Fixed.
[ May 23, 2006: Message edited by: Ken Blair ]
 
I was her plaything! And so was this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic