我正在尝试将以下代码更改为StringBuilder
,以便可以格式化ArrayList
的输出。
private static String createFormattedList(List<List<String>> failureList) {
String lineBreak = "</br>";
String result = "";
for (List<String> failure : failureList) {
for (String item : failure) {
result += item + lineBreak;
}
result += lineBreak;
}
return result;
}
答案 0 :(得分:2)
使用以下代码:
private static String createFormattedList(List<List<String>> failureList) {
String lineBreak = "</br>";
StringBuilder result = new StringBuilder();
for (List<String> failure : failureList) {
for (String item : failure) {
result.append(item).append(lineBreak);
}
result.append(lineBreak);
}
return result.toString();
}