Class IntList
java.lang.Object
cloud.opencode.base.collections.primitive.IntList
- All Implemented Interfaces:
Serializable, Iterable<Integer>
IntList - Primitive int List
IntList - 原始 int 列表
A resizable array implementation for primitive int values. Avoids boxing overhead of Integer objects.
原始 int 值的可调整大小数组实现。避免 Integer 对象的装箱开销。
Features | 主要功能:
- No boxing overhead - 无装箱开销
- Memory efficient - 内存高效
- Random access - 随机访问
- Resizable - 可调整大小
- Stream support - 流支持
Usage Examples | 使用示例:
// Create empty - 创建空
IntList list = IntList.create();
// Create with capacity - 创建指定容量
IntList list = IntList.create(100);
// Create from values - 从值创建
IntList list = IntList.of(1, 2, 3, 4, 5);
// Operations - 操作
list.add(10);
list.addAll(1, 2, 3);
int value = list.get(0);
list.set(0, 100);
// Stream - 流
int sum = list.stream().sum();
Performance | 性能特性:
- get/set: O(1) - get/set: O(1)
- add: O(1) amortized - add: O(1) 均摊
- contains: O(n) - contains: O(n)
Security | 安全性:
- Thread-safe: No - 线程安全: 否
- Null-safe: N/A (primitive) - 空值安全: 不适用(原始类型)
- Since:
- JDK 25, opencode-base-collections V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionvoidadd(int value) Add element.voidadd(int index, int value) Add element at index.voidaddAll(int... values) Add all values.doubleaverage()Return the average.voidclear()Clear all elements.booleancontains(int value) Check if contains value.static IntListcreate()Create an empty IntList.static IntListcreate(int initialCapacity) Create an IntList with initial capacity.booleanvoidforEach(IntConsumer action) ForEach with primitive consumer.intget(int index) Get element at index.inthashCode()intindexOf(int value) Find index of value.booleanisEmpty()Check if empty.iterator()intlastIndexOf(int value) Find last index of value.intmax()Return the maximum.intmin()Return the minimum.static IntListof(int... values) Create an IntList from values.Return primitive iterator.static IntListrange(int start, int end) Create an IntList from a range.booleanremove(int value) Remove first occurrence of value.intremoveAt(int index) Remove element at index.voidreverse()Reverse in place.intset(int index, int value) Set element at index.intsize()Return the size.voidsort()Sort in place.stream()Return as stream.longsum()Return the sum.int[]toArray()Return as array.toString()Methods inherited from interface Iterable
forEach, spliterator
-
Method Details
-
create
Create an empty IntList. 创建空 IntList。- Returns:
- new IntList | 新的 IntList
-
create
Create an IntList with initial capacity. 创建指定初始容量的 IntList。- Parameters:
initialCapacity- initial capacity | 初始容量- Returns:
- new IntList | 新的 IntList
-
of
Create an IntList from values. 从值创建 IntList。- Parameters:
values- the values | 值- Returns:
- new IntList | 新的 IntList
-
range
Create an IntList from a range. 从范围创建 IntList。- Parameters:
start- start (inclusive) | 开始(包含)end- end (exclusive) | 结束(不包含)- Returns:
- new IntList | 新的 IntList
-
size
public int size()Return the size. 返回大小。- Returns:
- size | 大小
-
isEmpty
public boolean isEmpty()Check if empty. 检查是否为空。- Returns:
- true if empty | 如果为空则返回 true
-
get
public int get(int index) Get element at index. 获取索引处的元素。- Parameters:
index- the index | 索引- Returns:
- element | 元素
-
set
public int set(int index, int value) Set element at index. 设置索引处的元素。- Parameters:
index- the index | 索引value- the value | 值- Returns:
- old value | 旧值
-
add
public void add(int value) Add element. 添加元素。- Parameters:
value- the value | 值
-
add
public void add(int index, int value) Add element at index. 在索引处添加元素。- Parameters:
index- the index | 索引value- the value | 值
-
addAll
public void addAll(int... values) Add all values. 添加所有值。- Parameters:
values- the values | 值
-
removeAt
public int removeAt(int index) Remove element at index. 移除索引处的元素。- Parameters:
index- the index | 索引- Returns:
- removed value | 移除的值
-
remove
public boolean remove(int value) Remove first occurrence of value. 移除第一次出现的值。- Parameters:
value- the value | 值- Returns:
- true if removed | 如果移除则返回 true
-
clear
public void clear()Clear all elements. 清除所有元素。 -
contains
public boolean contains(int value) Check if contains value. 检查是否包含值。- Parameters:
value- the value | 值- Returns:
- true if contains | 如果包含则返回 true
-
indexOf
public int indexOf(int value) Find index of value. 查找值的索引。- Parameters:
value- the value | 值- Returns:
- index, or -1 | 索引,或 -1
-
lastIndexOf
public int lastIndexOf(int value) Find last index of value. 查找值的最后索引。- Parameters:
value- the value | 值- Returns:
- index, or -1 | 索引,或 -1
-
sum
public long sum()Return the sum. 返回总和。- Returns:
- sum | 总和
-
min
public int min()Return the minimum. 返回最小值。- Returns:
- minimum | 最小值
- Throws:
NoSuchElementException- if empty | 如果为空
-
max
public int max()Return the maximum. 返回最大值。- Returns:
- maximum | 最大值
- Throws:
NoSuchElementException- if empty | 如果为空
-
average
public double average()Return the average. 返回平均值。- Returns:
- average | 平均值
- Throws:
NoSuchElementException- if empty | 如果为空
-
toArray
public int[] toArray()Return as array. 返回数组。- Returns:
- array | 数组
-
stream
-
sort
public void sort()Sort in place. 就地排序。 -
reverse
public void reverse()Reverse in place. 就地反转。 -
primitiveIterator
Return primitive iterator. 返回原始迭代器。- Returns:
- primitive iterator | 原始迭代器
-
iterator
-
forEach
ForEach with primitive consumer. 使用原始消费者的 forEach。- Parameters:
action- the action | 动作
-
equals
-
hashCode
-
toString
-