英文:
Combining items from custom class
问题
我有以下代码:
List<String> namesList = aList.stream()
.map(rollingD::getSettDate)
.collect(Collectors.toList());
List<String> namesList1 = aList.stream()
.map(rollingD::getPublishingPeriodCommencingTime)
.collect(Collectors.toList());
PublishingPeriodCommencingTime 和 SettDate 都存在于同一个列表中。
如何将这两个项目合并,以便我可以获得 getSettDate + " " + getPublishingPeriodCommencingTime
getSettDate 的格式类似于例如 01/01/2020,而 getPublishingPeriodCommencingTime 的格式类似于例如 01:10:33
我希望获得类似于 dd/mm/yyyy hh:MM:ss 的日期时间戳。
英文:
I have the following
List<String> namesList = aList.stream()
.map(rollingD::getSettDate)
.collect(Collectors.toList());
and
List<String> namesList1 = aList.stream()
.map(rollingD::getPublishingPeriodCommencingTime)
.collect(Collectors.toList());
The PublishingPeriodCommencingTime and the SettDate both exist from the same list.
How can i combine my two items so that i can get getSettDate +" "+ getPublishingPeriodCommencingTime
getSettDate looks like for example 01/01/2020 and the getPublishingPeriodCommencingTime looks like for example 01:10:33
I want to obtain a date time stamp like dd/mm/yyyy hh:MM:ss
答案1
得分: 3
List<String> stamps = IntStream.range(0, nameList.size())
.map(i -> nameList.get(i) + " " + nameList1.get(i))
.collect(Collectors.toList())
但是为什么不使用原始的列表呢?
List<String> stamps = aList.stream()
.map(x -> x.getSettDate() + " " + x.getPublishingPeriodCommencingTime())
.collect(Collectors.toList());
英文:
List<Strings> stamps = IntStream.range(0, nameList.size())
.map(i->nameList.get(i) + " " + nameList1.get(i))
.collect(Collectors.toList())
But why not use the original list?
List<String> stamps = aList.stream()
.map(x->x.getSettDate() + " " + x.getPublishingPeriodCommencingTime())
.collect(Collectors.toList());
答案2
得分: 0
List<String> namesList = aList.stream()
.map(rollingD -> rollingD.getSettDate() + " " +
rollingD.getPublishingPeriodCommencingTime())
.collect(Collectors.toList());
英文:
List<String> namesList = aList.stream()
.map(rollingD -> rollingD.getSettDate() + " " +
rollingD.getPublishingPeriodCommencingTime())
.collect(Collectors.toList());
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论