• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

A question about Vectors

 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My question is can I create a multidimesional Vector as is possible with Arrays? Can I create a Vector of Vectors? The reason i ask is because I want to create a matrix that does not have an initial size.
Thank you for your help.
 
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess so though I have never tried it. Are you getting any error?
 
kevin comario
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually i dont know how to do it. I was hoping someone knew? That is why I was asking if its possible to do so. I'm kinda lost.
 
Ranch Hand
Posts: 442
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sure you can, with no limit either, besides memory of course

and so on
just remember that you're adding objects, so cast correctly when you get the objects back
 
kevin comario
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry to bother you all again but. I am still a little confused. See what i want to do is create a matrix using vectors sort of like you do with multi-dimensional arrays. Like this:

but with vectors is there anyway of doing so.
If not thanks for the help anyway.
 
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You will have to do something like this.


for(int k = 0; k < 10; k++){for(int i = 0; i < 10; i++){matrix[k][i] = Integer.parseInt(st.nextToken());}}

 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In a 2-dimensional array each element of the array is another array. Similarly each element of the Vector can be another Vector. Is that what you want ?

Now when u want to update for the first element

Thus it can grow in both the dimensions indefinitely
 
kevin comario
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Sabarish. I couldnt see it before now, i knew it was possible but was not sure how to do it. Once again thanks.
 
Any sufficiently advanced technology will be used as a cat toy. And this tiny ad contains a very small cat:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic