I want to get one Object with List<> fields from list of objects with no List<> fields.
This is my code:
public class ObjectDTO {
private List<String> ids;
private List<Date> times;
private List<String> names;
private List<String> details;
public class ObjectDTOHelper {
private String id;
private Date time;
private String name;
private String detail;
}
I supply List<ObjectDTOHelper>
as input and want to get output just an object of ObjectDTO
.
Which I can solve with multiple independent stream functions:
List<ObjectDTOHelper> helpers; //about 1000 elements
List<String> ids= helpers.stream().map(h -> h.id).collect(toList());
List<Date> times= helpers.stream().map(h -> h.time).collect(toList());
List<String> names= helpers.stream().map(h -> h.name).collect(toList());
List<String> details= helpers.stream().map(h -> h.detail).collect(toList());
new ObjectDTO(ids, times, name, detail)
Which I think is not the best solution, because I need do that more 100_000 times)
Can you help solve this more optimally?