Skip to content

Proposal: Replace Collectors.toList() with new ArrayList<>(collection) for Clarity and Performance #103

@SaFE-APIOpt

Description

@SaFE-APIOpt

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions