英文:
In Java SWT, i am trying to display few information in a seperate console. Is it possible to display list of items to be displayed in the console?
问题
propertyConsole.setText("\n 项目名称:" + item1.projectName + ".act"
- " " + "\n\n 分类: " + item1.category + " "
- "\n\n 模块: " + item1.modulesList[]);
在Java SWT中,我尝试在一个单独的控制台中显示一些信息。是否可以在控制台中显示要显示的项目列表?modulesList实际上是一个包含4或5个项目的列表,需要显示在控制台中。
英文:
propertyConsole.setText("\n Project Name:" + item1.projectName + ".act"
+ " " + "\n\n Category: " + item1.category + " "
+ "\n\n Modules: " + item1.modulesList[]);
In Java SWT, i am trying to display few information in a seperate console. Is it possible to display list of items to be displayed in the console? The modulesList is actually a list of 4 or 5 items which need to be displayed in the console
答案1
得分: 1
您可以使用 Arrays#toString 方法来返回给定数组的 String 表示。
这是一个示例。
String[] strings = { "abc", "def", "ghi" };
System.out.println(Arrays.toString(strings));
输出
[abc, def, ghi]
此外,您可以使用 StringBuilder 和 Formatter 类来组织您的 String 值,可能会很有用。
另外,Formatter 类的 JavaDoc 提供了广泛的格式说明符集合。
Formatter (Java SE 20 & JDK 20) – Conversions。
StringBuilder string = new StringBuilder();
Formatter formatter = new Formatter(string);
formatter.format("Project Name: %s.act%n", item1.projectName);
formatter.format("Category: %s%n", item1.category);
formatter.format("Modules: %s", Arrays.toString(item1.modulesList));
formatter.flush();
propertyConsole.setText(string.toString());
英文:
You can use the Arrays#toString method to return a String representation of a given array.
Here is an example.
String[] strings = { "abc", "def", "ghi" };
System.out.println(Arrays.toString(strings));
Output
[abc, def, ghi]
Furthermore, you may find it useful to organize your String value by utilizing the StringBuilder and Formatter classes.
Additionally, the Formatter class JavaDoc provides the extensive set of format specifiers.
Formatter (Java SE 20 & JDK 20) – Conversions.
StringBuilder string = new StringBuilder();
Formatter formatter = new Formatter(string);
formatter.format("Project Name: %s.act%n", item1.projectName);
formatter.format("Category: %s%n", item1.category);
formatter.format("Modules: %s", Arrays.toString(item1.modulesList));
formatter.flush();
propertyConsole.setText(string.toString());
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论