Append a string to Vector element
Hi again, I don't find any method that append my string to the vector element.
Code java:
Vector<String> v = new Vector<String>();
...
for(int i=0; i<v.size() ;i++)
v.elementAt(i).concat(" hello");
This just return the v.elementAt(i) with " hello" at the end. but doesn't modify the element. So i should asignate the returned string to other variable .
I can't do this asignation: v.elementAt(i) = v.elementAt(i).concat(" hello");
Imagine all v.elements has 1234 already. Now I want to concat this (I want this output):
v.elementAt(0) = "1234 hello"
v.elementAt(1) = "1234 hello"
v.elementAt(2) = "1234 hello"
but I only get
v.elementAt(0) = "1234"
or
v.elementAt(0) = " hello"
If I use this i get replaced 1234 for hello, instead append it
Code java:
for(int i=0; i<v.size() ;i++)
v.add(i, "hello");
Re: Append a string to Vector element
The Vector class has other methods that may be useful to get and set its contents.
Re: Append a string to Vector element
Hehe I'm lucky I know a bit about setter and getter :D:D, otherwise I could not understand you :P.
Didn't expect that I could do this.
Thank you-
SOLVED:
Code java:
for(int i=0; i<v.size() ;i++){
v.set(i, v.get(i)+" hello");
System.out.println(v.elementAt(i));
}