With advent of java8 , we can create the html table in pure java by using stream api .
final Map<String,Integer> map = new HashMap<>();
map.put("key1", 5);
map.put("key2", 7);
String tableBody =
map.keySet()
.stream()
.map(item -> new StringBuilder("<tr><td>")
.append(item)
.append("</td><td>")
.append(String.valueOf(map.get(item)))
.append("</td></tr>")
)
.collect(Collectors.joining());
String tableContent = "<table>" + tableBody + "</table>";
System.out.println("tableContent = "+tableContent);
To create a table in jsp from a map , better opt for JSTL.
<table>
<c:forEach var="entry" items="${mapObj}">
<tr><td>${entry.key}</td> <td><${entry.value}</td></tr>
</c:forEach>
</table>