954,536 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

require separator between sections (sets of rows.)

I have a table that outputs certain rows.But they are from different groups and the different groups are stored in different vectors.At present i am adding all the rows using the following code :

m_vector.addAll(match1);
m_vector.addAll(match2);
..
m_vector.addAll(matchn);

Here match 1 to match n are the different sections.I Want to insert rows in between these statements that act as separators of these sections.


Now I want to add a separator between different sections (a group of rows) of my table. And I want to be able to put text in it too, to describe what the different sections are about. What is the best approach to do this, especially in terms of simplicity of implementation (cause I already have a bunch of code working a certain way, I want to minimize the changes, if any needed...).

adity
Newbie Poster
23 posts since Feb 2007
Reputation Points: 10
Solved Threads: 0
 

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
Team Colleague
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?

adity
Newbie Poster
23 posts since Feb 2007
Reputation Points: 10
Solved Threads: 0
 
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
Team Colleague
3,329 posts since Dec 2007
Reputation Points: 1,014
Solved Threads: 448
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: