Skip to content

[Code Issue] Copying collections immutably #140

@aleksandy

Description

@aleksandy

Category

collections

Pattern slug

copying-collections-immutably

Which code is affected?

Collections.unmodifiableList(input)

Type of issue

This is not an equivalent replacement for the old code, because List.copyOf(Collection) copies the collection, whereas Collections.unmodifiableList(List) just wraps it in a read-only wrapper.

Describe the issue

The new method requires twice as much memory, and its execution time depends on the size of the input collection.

The memory utilization and execution time of the old method is constant and does not depend on the size of the input collection.

JDK version tested

9+

Metadata

Metadata

Labels

bugSomething isn't workingslugNew or updated pattern snippet (category/slug.json)

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions