Class ImmutableList<E>

java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractList<E>
cloud.opencode.base.collections.ImmutableList<E>
Type Parameters:
E - element type | 元素类型
All Implemented Interfaces:
Serializable, Iterable<E>, Collection<E>, List<E>, RandomAccess, SequencedCollection<E>

public final class ImmutableList<E> extends AbstractList<E> implements RandomAccess, Serializable
ImmutableList - Immutable List Implementation ImmutableList - 不可变列表实现

A list that cannot be modified after creation. Any attempt to modify the list will throw an exception.

创建后不能修改的列表。任何修改列表的尝试都会抛出异常。

Features | 主要功能:

  • Immutable - 不可变
  • Thread-safe - 线程安全
  • Null-safe (nulls not allowed) - 空值安全(不允许空值)
  • Random access - 随机访问

Usage Examples | 使用示例:

// Create from elements - 从元素创建
ImmutableList<String> list = ImmutableList.of("a", "b", "c");

// Create from collection - 从集合创建
ImmutableList<String> list = ImmutableList.copyOf(existingList);

// Use builder - 使用构建器
ImmutableList<String> list = ImmutableList.<String>builder()
    .add("a")
    .addAll(Arrays.asList("b", "c"))
    .build();

Performance | 性能特性:

  • get: O(1) - get: O(1)
  • contains: O(n) - contains: O(n)
  • iteration: O(n) - iteration: O(n)

Security | 安全性:

  • Thread-safe: Yes (immutable) - 线程安全: 是(不可变)
  • Null-safe: Yes (nulls not allowed) - 空值安全: 是(不允许空值)
Since:
JDK 25, opencode-base-collections V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also: