Forums Register Login

Vector increase my adding indice to next

+Pie Number of slices to send: Send
Hello everyone
I am adding collection first element at position 2, which is fine and add it to my requeire position but when i add another at position 1, it moves my previos added collection to 3 but it must remain at the same position whihc i ve added mean postion 2, why it is doing so because i ve to recover these values at the end and if my indices change then it is big problem for me, is there any way around.

here is my sample code

import java.util.*;

public class VChk{
Vector store;
public VChk(){
store = new Vector(10);
store.setSize(10);

}

public void addingVal(int val, String str){
Vector v = new Vector();

v.addElement(str);
addingTOStore(val, v);

}

public void addingTOStore(int val, Vector v){
System.out.println("size "+ store.size());
store.add(val, v);
System.out.println(store);
}


public static void main(String [] arg){
VChk a = new VChk();

a.addingVal(2,"str2");
a.addingVal(1,"str1");
}

}
+Pie Number of slices to send: Send
disregard my posting, i figure it out , i can use setElementAt instead of calling add ...

cheers
You can't expect to wield supreme executive power just because
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 658 times.
Similar Threads
please explain
Please Help: Putting Vector objects into HashMap
Problem with Array Value - Comparing Arrays.
Why am I getting this error?
Help with adding elements to vector
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 09:43:18.