If you happen to use a recent versions of Java, you can take avantage of text blocks, i.e. """
(which were introduced as a preview feature in Java 13). They greatly increase the readability of your code by getting the double quotes out of the way while being formattable with the formatted
method (similar to String format
) :
String htmlTable = """
<html>
<head></head>
<body>
<table>
<tr>
<th> ClientName </th>
<th> SyncCount </th>
</tr>
%s
</table>
</body>
</html>""".formatted(
// Lignes du tableau pour chaque document à retourner
metricsList.stream().map(metrics -> """
\n
<tr>
<td>%s</td>
<td>%s</td>
</tr>""".formatted(
metrics.getName(),
metrics.getSyncCall())
).collect(Collectors.joining())
);
In the above code the %s
in the first text block is replaced with the html for the table data rows which in turn is generated by iterating over the object list with a stream
function which map
each object to a string that gets concatenated with the ending .collect(Collectors.joining())
.
If you happen to use a recent versions of Java, you can take avantage of text blocks, i.e. """
(which were introduced as a preview feature in Java 13). They greatly increase the readability of your code by getting the double quotes out of the way while being formattable with the formatted
method (similar to String format
) :
String htmlTable = """
<html>
<head></head>
<body>
<table>
<tr>
<th> ClientName </th>
<th> SyncCount </th>
</tr>
%s
</table>
</body>
</html>""".formatted(
// Lignes du tableau pour chaque document à retourner
metricsList.stream().map(metrics -> """
\n
<tr>
<td>%s</td>
<td>%s</td>
</tr>""".formatted(
metrics.getName(),
metrics.getSyncCall())
).collect(Collectors.joining())
);
In the above code the %s
in the first text block is replaced with the html for the table data rows which in turn is generated by iterating over the object list with a stream
function which map
each object to a string that gets concatenated with the ending .collect(Collectors.joining())
.
If you happen to use a recent versions of Java, you can take avantage of text blocks, i.e. """
(which were introduced as a preview feature in Java 13). They greatly increase the readability of your code by getting the double quotes out of the way while being formattable with the formatted
method (similar to String format
) :
String htmlTable = """
<html>
<head></head>
<body>
<table>
<tr>
<th> ClientName </th>
<th> SyncCount </th>
</tr>
%s
</table>
</body>
</html>""".formatted(
metricsList.stream().map(metrics -> """
\n
<tr>
<td>%s</td>
<td>%s</td>
</tr>""".formatted(
metrics.getName(),
metrics.getSyncCall())
).collect(Collectors.joining())
);
In the above code the %s
in the first text block is replaced with the html for the table data rows which in turn is generated by iterating over the object list with a stream
function which map
each object to a string that gets concatenated with the ending .collect(Collectors.joining())
.
If you happen to use a recent versions of Java, you can take avantage of text blocks, i.e. """
(which were introduced as a preview feature in Java 13). They greatly increase the readability of your code by getting the double quotes out of the way while being formattable with the formatted
method (similar to String format
) :
String htmlTable = """
<html>
<head></head>
<body>
<table>
<tr>
<th> ClientName </th>
<th> SyncCount </th>
</tr>
%s
</table>
</body>
</html>""".formatted(
// Lignes du tableau pour chaque document à retourner
metricsList.stream().map(metrics -> """
\n
<tr>
<td>%s</td>
<td>%s</td>
</tr>""".formatted(
metrics.getName(),
metrics.getSyncCall())
).collect(Collectors.joining())
);
In the above code the %s
in the first text block is replaced with the html for the table data rows which in turn is generated by iterating over the object list with a stream
function which map
each object to a string that gets concatenated with the ending .collect(Collectors.joining())
.