wood burning stoves*
The moose likes Beginning Java and the fly likes Vector increase my adding indice to next Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Vector increase my adding indice to next" Watch "Vector increase my adding indice to next" New topic
Author

Vector increase my adding indice to next

ghazanfar khan
Ranch Hand

Joined: Apr 18, 2005
Posts: 81
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");
}

}
ghazanfar khan
Ranch Hand

Joined: Apr 18, 2005
Posts: 81
disregard my posting, i figure it out , i can use setElementAt instead of calling add ...

cheers
 
Don't get me started about those stupid light bulbs.
 
subject: Vector increase my adding indice to next
 
Similar Threads
Why am I getting this error?
Please Help: Putting Vector objects into HashMap
Problem with Array Value - Comparing Arrays.
please explain
Help with adding elements to vector