2

Hi when you have a look at MBeans classes you will come to know few classes also return data in tabular data format of java. Can anyone let me know what is this and how i can save tabular data format in to a string array list.

Java Doc Link

amod
  • 4,190
  • 10
  • 49
  • 75

2 Answers2

3

To convert the TabularData to a list of strings containing the values of each row in the table, you can use something like this.

(Note that TabularData is an interface - TabularDataSupport is one implementation. MBeans may use their own implementation, so it's best to code to the interface rather than the implementation class.)

String SEPARATOR = " ";  // change this as needed, e.g. to tab, comma etc.
TabularData data = ...; // data from the mbean
List<String> list = new ArrayList<String>();  // the output list
for (Object v: data.values()) {
   CompositeData row = (CompositeData)v;
   StringBuilder rowString = new StringBuilder();
   for (Object rv: row.values()) {
       if (rowString.length()!=0)
            rowString.append(SEPARATOR);
       rowString.append(rv);
   }
   list.add(rowString.toString());
}
mdma
  • 56,943
  • 12
  • 94
  • 128
-1

You could try returning List<List<Object>>.
Each element of the outer List is a "row".
Each element of the inner Lists is a "column" of the "row".

Bohemian
  • 412,405
  • 93
  • 575
  • 722
  • this approach could have been usefull when i m taking data one by one and want to save as table(logical table), but when it comes to jms you have a data type like table know as TabularDataSupport datatype... i have added link above... – amod Aug 01 '11 at 14:34