aspose file tools*
The moose likes JSP and the fly likes Vector Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Vector" Watch "Vector" New topic
Author

Vector

Joey Alencar
Ranch Hand

Joined: Jun 26, 2001
Posts: 43
I'd like to know how can I implement a Vector (or anything like this) of a Class. It's like a array of a class.
Thanks.
Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1510
Can you elaborate? Do you mean how to manipulate instances of your class using a vector or what?

Bosun


Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley
Joey Alencar
Ranch Hand

Joined: Jun 26, 2001
Posts: 43
I have one class and I'd like to create a Vector (or array) of this class. I'd like to know how can I implement and manipulate this (input and get values).
Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

Umm.. at the risk of being too obvious In this example, 'v' is a Vector containing instances of your class.

Did you mean that you wanted your class to *be* a Vector-like object? ie:
In this case, you can extend Vector ie: "public class MyClass extends Vector"
Joey Alencar
Ranch Hand

Joined: Jun 26, 2001
Posts: 43
OK, but how can I get the values of my class's variables using this Vector?
Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1510
To get the values of your class variables, you need to cast the contents of the vector to the appropriate type, in this case your class type. You can use the enumeration interface to go through the vector.
for(Enumeration c = yourVector.elements(); c.hasMoreElements(); ){
yourClassType s = (yourClass) c.nextElement()
s.yourmethod/variable name
}
I hope this helps.


------------------
Bosun
SCJP for the Java� 2 Platform
Tony Alicea
Desperado
Sheriff

Joined: Jan 30, 2000
Posts: 3222
    
    5
I am moving this thread to the Java Beginner forum. It doesn't belong in this one


Tony Alicea
Senior Java Web Application Developer, SCPJ2, SCWCD
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Vector