IT-Consulting · Soft- & Hardware Engineering & Development · IoT · AI · Green-/Boat-/Navi-/Fin-Tech

Transforming Data – Clean and Efficient

Data Transformation Without Overhead

Transforming collections is common, but Streams create intermediate objects and allocations. When transformations are repeated frequently, simple loops are far more efficient.

Benchmark (1,000 elements, repeated 100,000 times):

For loop: ~35–60 ms total
Stream: ~1,000–1,400 ms total

Example

Instead of

List names = users.stream()
    .map(User::getName)
    .collect(Collectors.toList());

Use:

List names = new ArrayList<>(users.size());
for(User u:users)
{ names.add(u.getName());
}

Why this matters

Streams Make Sense When

Cloud Considerations

In serverless/cloud functions, repeated Stream creation increases memory allocations and runtime cost. Lean loops reduce both execution time and resource footprint, making them more cost-effective at scale.

Takeaway

Elegance doesn’t require abstraction. Machine-near, clean loops combine high performance, maintainability, and cost efficiency—even in cloud environments.

#Java #Transforming #Performance #ForLoop #Streams #CleanCode #JVM #CodingEfficiency #MachineNear #CloudJava