• Post Reply Bookmark Topic Watch Topic
  • New Topic

Add elements to a Vector  RSS feed

 
Peter Simon
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am writing a method that has to add several elements to a vector.
Each element needs to be named differently off course.
What I need to do is add a number to the instancename.
like this:

Can someone tell me what is the correct syntax?
 
William Barnes
Ranch Hand
Posts: 1048
2
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What I find strange about the code is how you are using the Cabin class. You make a new Cabin each time through the loop. And I don't think you can do this:

You are creating an instance of the class and attempting to assign to it all at the same time.
Make the class than call a set method to assign the primary key.
 
Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This can't be correct:
Cabin cab(i)=
You want to do something like:
Cabin cabin =
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Peter, I don't think that I quite understand your question.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!