Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 155
  • Last Modified:

Two-dimensional array-object to HTML-table

Hi!

I have a two-dimensional array-object (e.g. String[][]) which I want to present in a HTML-table.

Is there an easy way to do this without using JSP etc.?

The point is that I need something simple like System.out.println() in the development process.

Regards,
Jesper
0
jespersahner
Asked:
jespersahner
  • 3
1 Solution
 
CEHJCommented:
Something like


StringBuilder sb = new StringBuilder();
sb.append("<table>");
for(int i = 0;i < matrix.length;i++) {
      sb.append("<tr>");
      for(int j = 0;j < matrix[i].length;j++) {
            sb.append("<td>").append(matrix[i][j].append("</td>");
      }
      sb.append("<tr>");  
}
sb.append("</table>");
String table = sb.toString();

0
 
CEHJCommented:
Typo. Second

>>     sb.append("<tr>");  

should be

     sb.append("</tr>");  

0
 
jespersahnerAuthor Commented:
->CEHJ: That is a very direct approach, think it will do perfect for this.

Thanks for your quick input!

Regards,
Jesper
0
 
CEHJCommented:
No problem

:-)
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now