Results 1 to 4 of 4
Thread: Naming Variables
- 05-07-2010, 03:29 PM #1
Member
- Join Date
- Mar 2009
- Posts
- 45
- Rep Power
- 0
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
- 05-07-2010, 03:39 PM #2
Senior Member
- Join Date
- Dec 2008
- Location
- Kolkata
- Posts
- 280
- Rep Power
- 5
Yes, you are right, its getting overwritten. So how about using a Student type array?
Swastik
- 05-07-2010, 04:36 PM #3
Member
- Join Date
- Mar 2009
- Posts
- 45
- Rep Power
- 0
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?
- 05-07-2010, 04:40 PM #4
Similar Threads
-
Variable Naming
By 67726e in forum Advanced JavaReplies: 2Last Post: 03-30-2010, 08:55 AM -
What are Instance variables and static variables?
By sandeshforu in forum New To JavaReplies: 3Last Post: 09-09-2009, 05:48 PM -
Naming a Class
By Java Tip in forum Java TipReplies: 0Last Post: 12-22-2007, 11:21 AM -
RMI naming problem
By Robbinz in forum New To JavaReplies: 1Last Post: 12-06-2007, 11:32 PM -
Naming conventions
By Java Tip in forum Java TipReplies: 0Last Post: 12-03-2007, 09:53 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks