如何将结果集放入数组列表

How to put ResultSet to List of Array

我正在尝试将 ResultSet 放入 List 中。这是我的代码

List<CSVRaportDescription[]> result = new ArrayList<>();
List<CSVRaportDescription> csvRaportDescList = new ArrayList<>();
ResultSet resultSet = dataSource.executeQuery(query.toString().replace("?", dayList.toString()));
resultSet.forEach(row->{
    csvRaportDescList.add(new CSVRaportDescription(row.getObject("value")));
});
CSVRaportDescription[] csvRaportArray = csvRaportDescList.toArray(new CSVRaportDescription[csvRaportDescList.size()]);
result.add(csvRaportArray);

有什么方法可以让它更快?

首先,我将结果集放入 List,然后放入 Object[],最后将其添加到 List。这似乎是最长的方法,但我无法将其重构为更好的质量。

如果流式传输结果 List,则可以跳过中间列表。

CSVRaportDescription[] result = resultSet.all().stream()
    .map(row -> new CSVRaportDescription(row.getObject("value")))
    .toArray(CSVRaportDescription[]::new);
return Collections.singletonList(result);

这是否更快,您必须衡量。