Java Vector Problem

Status
You're currently viewing only fejta's posts. Click here to go back to viewing the entire thread.
Not open for further replies.

fejta

Ars Scholae Palatinae
844
First off, why can't you create new classes? That's really stupid. If you can't create new classes, you might as well use c. (Not even a class inside the applet class??)

But anyway...It looks like you only need to find people's names based on their ages. So why don't you create a Vector for each person and put both their name and age inside?

ie:
Code:
int age;
String name;
Vector person = new Vector(2); //define the size. since it won't change, you'll save memory.
person.add(name);
person.add(new Integer(age);

Now instead of having one vector for each persons age and a separate one for their name, you just have one vector that stores all the people (which are represented as vectors).

ie instead of going
Code:
Vector names;
Vector ages;

int his_age = ages.get();
String his_name = names.get();


Do this:
Code:
Vector people;

Vector person = people.get();
int his_age =  person.get(1);
String his_name = person.get(0);

I'd do something along those lines, rather than having two vectors or use a hashtable, which doesn't make any sense unless you need to quickly find out whether a person's name is in your list or not.
 
Status
You're currently viewing only fejta's posts. Click here to go back to viewing the entire thread.
Not open for further replies.