Combining items from custom class

Viewed 56

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

2 Answers
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());
     List<String> namesList = aList.stream()
                               .map(rollingD -> rollingD.getSettDate() + " " + 
                                    rollingD.getPublishingPeriodCommencingTime())
                               .collect(Collectors.toList());
Related