File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Add elements to a Vector Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Add elements to a Vector" Watch "Add elements to a Vector" New topic

Add elements to a Vector

Peter Simon

Joined: Oct 25, 2002
Posts: 14
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

Joined: Mar 16, 2001
Posts: 986

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.

Please ignore post, I have no idea what I am talking about.
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
This can't be correct:
Cabin cab(i)=
You want to do something like:
Cabin cabin =

Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
Dirk Schreckmann

Joined: Dec 10, 2001
Posts: 7023
Peter, I don't think that I quite understand your question.

[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
I agree. Here's the link:
subject: Add elements to a Vector
It's not a secret anymore!