If you look at the API of the Vector class you will see that there is a method that lets you add an element at a specific place. I think it is like this:
add(int i, Object obj);
Look at it, but if I remember correctly, it adds it to the int "place" and whatever was at that place it is shifted to the "end"
javaAddict
Nearly a Senior Poster
3,329 posts since Dec 2007
Reputation Points: 1,014
Solved Threads: 448
Yes there is a function that takes in an int and the object.But my vector is of a particular datastructure and I want to just enter a string in that row.Also i want to get the row dynamically..in the program.How do i achieve that?
You could do this:
Vector v = new Vector();
v.add("1");
v.add(someObject1);
v.add(someObject2);
v.add("2");
for (int i=0;i<v.size();i++) {
Object obj = v.get(i);
if (obj instanceof String) {
// seperate rows
} else if (obj instanceof SomeObject) {
SomeObject so = (SomeObject)v.get(i);
}
}
javaAddict
Nearly a Senior Poster
3,329 posts since Dec 2007
Reputation Points: 1,014
Solved Threads: 448