合并来自自定义类的项目

huangapple go评论101阅读模式
英文:

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&lt;String&gt; namesList = aList.stream()
                                   .map(rollingD::getSettDate)
                                   .collect(Collectors.toList());

and

List&lt;String&gt; 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&lt;Strings&gt; stamps = IntStream.range(0, nameList.size())
    .map(i-&gt;nameList.get(i) + &quot; &quot; + nameList1.get(i))
    .collect(Collectors.toList())

But why not use the original list?

List&lt;String&gt; stamps = aList.stream()
     .map(x-&gt;x.getSettDate() + &quot; &quot; + x.getPublishingPeriodCommencingTime())
     .collect(Collectors.toList());

答案2

得分: 0

List<String> namesList = aList.stream()
                           .map(rollingD -> rollingD.getSettDate() + " " + 
                                rollingD.getPublishingPeriodCommencingTime())
                           .collect(Collectors.toList());
英文:
     List&lt;String&gt; namesList = aList.stream()
                               .map(rollingD -&gt; rollingD.getSettDate() + &quot; &quot; + 
                                    rollingD.getPublishingPeriodCommencingTime())
                               .collect(Collectors.toList());

huangapple
  • 本文由 发表于 2020年4月8日 23:19:20
  • 转载请务必保留本文链接:https://go.coder-hub.com/61104169.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定