• 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

quick question about vectors

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello everyone,
I'd like to use vectors in my program instead of arrays because of the advantages of them being dynamic. Here is my question:
If I originally had an array of type "typeX" declared as such:
typeX[] array = new typeX[10];
How could I declare a vector of type typeX? I've tried:
typeX Vector myVector = new Vector();
but that doesn't seem to work.
Any help would be appreciated.
Thanks
 
Ranch Hand
Posts: 331
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Couple of things:
1. Use ArrayList instead. Vector basically shouldn't be used anymore.
2. Currently you can't declare an ArrayList to be of a certain type. You can add any Object to an ArrayList, but the drawback is that you usually have to cast them when you retrieve them in order for them to be useful. For example:

There is some kind of an initiative (or JRS or something like that) to add that functionality to the language. Check out this link on generics
 
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello Malcolm,
Blake's right there.
On your vector query, a vector object is of type Vector. So your 'typeX Vector myVector = new Vector()' will not work as the objects references contained in the vector object could be of different types. 'Vector myVector = new Vector();' will do.
[ February 25, 2003: Message edited by: boyet silverio ]
[ February 25, 2003: Message edited by: boyet silverio ]
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic