java - String[] 选项只显示一次
问题描述
显然该选项只显示一次,然后对每个位置重复该过程。我希望它一次显示所有选项,我假设我需要循环遍历 String[] 选项。有任何想法吗?
List < Location > locations = eventController.listLocations();
for (Location locationCategories: locations) {
String[] choices = {
locationCategories.getLocationName()
};
String locationName = (String) JOptionPane.showInputDialog(null, "Område navn der skal tilføjes til eventet",
"Område", JOptionPane.QUESTION_MESSAGE, null,
choices,
choices[0]);
解决方案
我了解您希望在单个JOptionPane
.
如果我理解正确,请尝试以下代码(使用流 API)
/*
* import java.util.stream.Collectors;
*/
List<Location> locations = eventController.listLocations();
String[] choices = locations.stream()
.map(Location::getLocationName)
.collect(Collectors.toList())
.toArray(new String[]{});
String locationName = (String) JOptionPane.showInputDialog(null,
"Område navn der skal tilføjes til eventet",
"Område",
JOptionPane.QUESTION_MESSAGE,
null,
choices,
choices[0]);
推荐阅读
- reactjs - Nextjs assets 404 Not Found 在 ssr 中使用动态路由时
- c# - 仅在 Windows 1803 版本中,UWP 应用程序很少崩溃并出现异常代码 0xc000027b
- flask - 通过裸域从电话重定向到 searchvity.com 访问烧瓶中的通配符页面
- vim - 如何让 fzf.vim 忽略 node_modules 和 .git 文件夹?
- java - AEM,Maven:重复的包名
- c# - 如何移动到列表中的下一个项目
- java - 默认情况下,Java Minidump 在 Windows 的客户端版本上未启用
- android - 我想破坏开始新意图的活动
- typescript - Typescript 隐式或显式断言窄类型平等
- excel - 根据单元格值从目录打开文件,跳过部分文件名2020(不打开)