我想从远程
获取名称和URLpublic interface Remote {
String getName();
Remote withName(String name);
String getUrl();
Remote withUrl(String url);
}
List<String> remoteNames = remoteList.stream().map(Remote::getName).filter(name -> name.equalsIgnoreCase(origin)).collect(Collectors.toList());
List<String> remoteUrls = remoteList.stream().map(Remote::GetUrl).filter(url-> url.equalsIgnoreCase(origin)).collect(Collectors.toList());
是否可以在一次调用中完成并将所有结果都放在一个变量中?
答案 0 :(得分:1)
创建一个包含两个字段的新类,并在map
时创建它:
List<NameAndURL> remotes = remoteList.stream().map(t -> new NameAndURL(t.getName(), t.getURL()))...