|
List<DynamicDataInstance> listData = data.stream().collect(Collectors.toList()); |
Change:
List<DynamicDataInstance> listData = data.stream().collect(Collectors.toList());
to:
List<DynamicDataInstance> listData = new ArrayList<>(data);
Collectors.toList() incurs additional Stream and Collector overhead, building intermediate objects and returning only a generic List without guaranteeing the concrete type. By contrast, new ArrayList<>(collection) leverages bulk copy via toArray(), avoids redundant allocations, and deterministically yields an ArrayList. Therefore, when the source is already a Collection, replacing Collectors.toList() with new ArrayList<>(collection) improves clarity, ensures type consistency, and provides better runtime performance.