【发布时间】:2020-10-11 00:14:35
【问题描述】:
如何在 Java 中打印用大括号分隔的字符串列表?例如,一个包含三个成员“Mother”、“Father”和“Daughter”的家庭应打印为
There is a family consists of { Mother, Father, Daughter }
或空的家庭
There is a family consists of { }
我写了这个,但它不能打印字符串列表:
String[] family = {" "};
String separator = "";
System.out.print("{ ");
for (String word : family) {
System.out.print(separator);
System.out.print(word);
separator = " ";
}
System.out.print(" }");
谢谢!
【问题讨论】:
-
到目前为止你尝试了什么?
-
我已将其添加到我的帖子中。谢谢!
标签: java arraylist printing comma curly-braces