• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Vector increase my adding indice to next

 
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 81
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
disregard my posting, i figure it out , i can use setElementAt instead of calling add ...

cheers
 
reply
    Bookmark Topic Watch Topic
  • New Topic