-
Naming Variables
Hi,
At the moment I am trying to make a method which takes as a parameter a vector. Just would like to know say for example if the size of a vector is unknown. And in the method to find this out I would do:
int vecSize= vectorName.size();
To find the size of the vector. What i'd like to know is say I wanted to extract these objects in the vector. So for example say vector v has size 3.
What is the best way to individually extract these?
I was thinking of making a for loop:
for(int i=0;i<vecSize;i++){
And then each turn of the loop it creates a new object from casting with the elementAt(i); method
But i'm unsure of how to extract these objects as if in the for loop body i done:
Student stu = (Student) vec.elementAt(i); //I made a student class to create student objects
For all loops only one student called stu is made and is overwritten after each loop i think.
Is there anyway to create a new individual object each loop or is there a better way of doing this
Thanks in advance
-
Yes, you are right, its getting overwritten. So how about using a Student type array?
-
Hi, this is a question for college which must use the vector as a parameter. I was looking at ArrayLists in the loop, but I am confused on how to make the multiple student objects in the for loop? Or am I going in the wrong direction?
-
u can make Vector itself as an array using toArray() method