English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

i really need some one to help me please !!

2007-02-22 12:23:02 · 4 answers · asked by jasmine 1 in Computers & Internet Programming & Design

4 answers

Vector v;

for (int i = 0; i < v.size (); i ++)
{
Object value = v.get (i);
// or if you're storing say Strings, you can do String value = (String)v.get (i);
System.out.println (value.toString ());
}

side note - in most cases, it's better to use ArrayList, not Vector - works faster. All the methods are still called the same.

2007-02-22 12:39:09 · answer #1 · answered by iluxa 5 · 0 0

Well, I could tell you how to iterate through a vector....
Printing depends on the object type stored in the vector.
Assuming the object is a String.

Vector theVector;
for(int i=0;i String s = (String)theVector.elementAt(i);
System.out.println(s);
}//end of for loop

I havent used Java in a while, but I think there is a new Vector that actually knows the object type--in which case you dont need to cast from object type.
Vector theVector;
for(int i=0;i String s = theVector.elementAt(i);
System.out.println(s);

}

2007-02-22 12:43:58 · answer #2 · answered by AL L 2 · 0 0

If the vector class implements the iterator interface (I've never used vector), then you could use this kind of for statement:

for (VectorClass i : v) //v is the collection of vectors
{
i.xxx //i will be initialized to point to each instance in v
}

2007-02-22 12:47:23 · answer #3 · answered by so far north 3 · 0 0

Michelle Obama.

2016-05-24 00:29:52 · answer #4 · answered by Anonymous · 0 0

fedest.com, questions and answers