Class LongList
java.lang.Object
cloud.opencode.base.collections.primitive.LongList
- All Implemented Interfaces:
Serializable, Iterable<Long>
LongList - Primitive long List
LongList - 原始 long 列表
A resizable array implementation for primitive long values. Avoids boxing overhead of Long objects.
原始 long 值的可调整大小数组实现。避免 Long 对象的装箱开销。
Features | 主要功能:
- No boxing overhead - 无装箱开销
- Memory efficient - 内存高效
- Random access - 随机访问
- Resizable - 可调整大小
- Stream support - 流支持
Usage Examples | 使用示例:
// Create empty - 创建空
LongList list = LongList.create();
// Create from values - 从值创建
LongList list = LongList.of(1L, 2L, 3L, 4L, 5L);
// Operations - 操作
list.add(10L);
long value = list.get(0);
// Stream - 流
long 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 index, long value) voidadd(long value) voidaddAll(long... values) doubleaverage()voidclear()booleancontains(long value) static LongListcreate()Create an empty LongList.static LongListcreate(int initialCapacity) Create a LongList with initial capacity.booleanvoidforEach(LongConsumer action) longget(int index) inthashCode()intindexOf(long value) booleanisEmpty()iterator()intlastIndexOf(long value) longmax()longmin()static LongListof(long... values) Create a LongList from values.static LongListrange(long start, long end) Create a LongList from a range.booleanremove(long value) longremoveAt(int index) voidreverse()longset(int index, long value) intsize()voidsort()stream()longsum()long[]toArray()toString()Methods inherited from interface Iterable
forEach, spliterator
-
Method Details
-
create
Create an empty LongList. 创建空 LongList。- Returns:
- new LongList | 新的 LongList
-
create
Create a LongList with initial capacity. 创建指定初始容量的 LongList。- Parameters:
initialCapacity- initial capacity | 初始容量- Returns:
- new LongList | 新的 LongList
-
of
Create a LongList from values. 从值创建 LongList。- Parameters:
values- the values | 值- Returns:
- new LongList | 新的 LongList
-
range
Create a LongList from a range. 从范围创建 LongList。- Parameters:
start- start (inclusive) | 开始(包含)end- end (exclusive) | 结束(不包含)- Returns:
- new LongList | 新的 LongList
-
size
public int size() -
isEmpty
public boolean isEmpty() -
get
public long get(int index) -
set
public long set(int index, long value) -
add
public void add(long value) -
add
public void add(int index, long value) -
addAll
public void addAll(long... values) -
removeAt
public long removeAt(int index) -
remove
public boolean remove(long value) -
clear
public void clear() -
contains
public boolean contains(long value) -
indexOf
public int indexOf(long value) -
lastIndexOf
public int lastIndexOf(long value) -
sum
public long sum() -
min
public long min() -
max
public long max() -
average
public double average() -
toArray
public long[] toArray() -
stream
-
sort
public void sort() -
reverse
public void reverse() -
primitiveIterator
-
iterator
-
forEach
-
equals
-
hashCode
-
toString
-