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>
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:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classBuilder for ImmutableList ImmutableList 构建器 -
Field Summary
Fields inherited from class AbstractList
modCount -
Method Summary
Modifier and TypeMethodDescriptionvoidbooleanbooleanaddAll(int index, Collection<? extends E> c) booleanaddAll(Collection<? extends E> c) static <E> ImmutableList.Builder<E> builder()Return a new builder.voidclear()booleanstatic <E> ImmutableList<E> Return an immutable list containing the elements of the given iterable.static <E> ImmutableList<E> copyOf(Collection<? extends E> elements) Return an immutable list containing the elements of the given collection.get(int index) intiterator()intlistIterator(int index) static <E> ImmutableList<E> of()Return an empty immutable list.static <E> ImmutableList<E> of(E e1) Return an immutable list containing the given element.static <E> ImmutableList<E> of(E... elements) Return an immutable list containing the given elements.static <E> ImmutableList<E> of(E e1, E e2) Return an immutable list containing the given elements.remove(int index) booleanbooleanremoveAll(Collection<?> c) voidreplaceAll(UnaryOperator<E> operator) booleanretainAll(Collection<?> c) intsize()voidsort(Comparator<? super E> c) Object[]toArray()<T> T[]toArray(T[] a) Methods inherited from class AbstractList
equals, hashCode, removeRange, subListMethods inherited from class AbstractCollection
containsAll, isEmpty, toStringMethods inherited from interface Collection
parallelStream, removeIf, stream, toArrayMethods inherited from interface List
addFirst, addLast, containsAll, getFirst, getLast, isEmpty, removeFirst, removeLast, reversed, spliterator
-
Method Details
-
of
Return an empty immutable list. 返回空不可变列表。- Type Parameters:
E- element type | 元素类型- Returns:
- empty immutable list | 空不可变列表
-
of
Return an immutable list containing the given element. 返回包含给定元素的不可变列表。- Type Parameters:
E- element type | 元素类型- Parameters:
e1- the element | 元素- Returns:
- immutable list | 不可变列表
-
of
Return an immutable list containing the given elements. 返回包含给定元素的不可变列表。- Type Parameters:
E- element type | 元素类型- Parameters:
e1- first element | 第一个元素e2- second element | 第二个元素- Returns:
- immutable list | 不可变列表
-
of
Return an immutable list containing the given elements. 返回包含给定元素的不可变列表。- Type Parameters:
E- element type | 元素类型- Parameters:
elements- the elements | 元素- Returns:
- immutable list | 不可变列表
-
copyOf
Return an immutable list containing the elements of the given collection. 返回包含给定集合元素的不可变列表。- Type Parameters:
E- element type | 元素类型- Parameters:
elements- the elements | 元素- Returns:
- immutable list | 不可变列表
-
copyOf
Return an immutable list containing the elements of the given iterable. 返回包含给定可迭代对象元素的不可变列表。- Type Parameters:
E- element type | 元素类型- Parameters:
elements- the elements | 元素- Returns:
- immutable list | 不可变列表
-
builder
Return a new builder. 返回新构建器。- Type Parameters:
E- element type | 元素类型- Returns:
- builder | 构建器
-
get
-
size
public int size()- Specified by:
sizein interfaceCollection<E>- Specified by:
sizein interfaceList<E>- Specified by:
sizein classAbstractCollection<E>
-
contains
- Specified by:
containsin interfaceCollection<E>- Specified by:
containsin interfaceList<E>- Overrides:
containsin classAbstractCollection<E>
-
indexOf
-
lastIndexOf
- Specified by:
lastIndexOfin interfaceList<E>- Overrides:
lastIndexOfin classAbstractList<E>
-
toArray
- Specified by:
toArrayin interfaceCollection<E>- Specified by:
toArrayin interfaceList<E>- Overrides:
toArrayin classAbstractCollection<E>
-
toArray
public <T> T[] toArray(T[] a) - Specified by:
toArrayin interfaceCollection<E>- Specified by:
toArrayin interfaceList<E>- Overrides:
toArrayin classAbstractCollection<E>
-
set
-
add
-
remove
-
add
- Specified by:
addin interfaceCollection<E>- Specified by:
addin interfaceList<E>- Overrides:
addin classAbstractList<E>
-
remove
- Specified by:
removein interfaceCollection<E>- Specified by:
removein interfaceList<E>- Overrides:
removein classAbstractCollection<E>
-
addAll
- Specified by:
addAllin interfaceCollection<E>- Specified by:
addAllin interfaceList<E>- Overrides:
addAllin classAbstractCollection<E>
-
addAll
-
removeAll
- Specified by:
removeAllin interfaceCollection<E>- Specified by:
removeAllin interfaceList<E>- Overrides:
removeAllin classAbstractCollection<E>
-
retainAll
- Specified by:
retainAllin interfaceCollection<E>- Specified by:
retainAllin interfaceList<E>- Overrides:
retainAllin classAbstractCollection<E>
-
clear
public void clear()- Specified by:
clearin interfaceCollection<E>- Specified by:
clearin interfaceList<E>- Overrides:
clearin classAbstractList<E>
-
replaceAll
- Specified by:
replaceAllin interfaceList<E>
-
sort
-
iterator
-
listIterator
- Specified by:
listIteratorin interfaceList<E>- Overrides:
listIteratorin classAbstractList<E>
-
listIterator
- Specified by:
listIteratorin interfaceList<E>- Overrides:
listIteratorin classAbstractList<E>
-