Class FloatList
java.lang.Object
cloud.opencode.base.collections.primitive.FloatList
- All Implemented Interfaces:
Serializable
FloatList - Primitive float List
FloatList - 原始 float 列表
A resizable array implementation for primitive float values. Avoids boxing overhead of Float objects.
原始 float 值的可调整大小数组实现。避免 Float 对象的装箱开销。
Features | 主要功能:
- No boxing overhead - 无装箱开销
- Memory efficient - 内存高效
- Random access - 随机访问
- Resizable - 可调整大小
Usage Examples | 使用示例:
// Create empty - 创建空
FloatList list = FloatList.create();
// Create from values - 从值创建
FloatList list = FloatList.of(1.0f, 2.0f, 3.0f);
// Operations - 操作
list.add(10.5f);
float value = list.get(0);
// Statistics - 统计
float sum = list.sum();
float avg = list.average();
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.3
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceFunctional interface for float consumer. float 消费者函数式接口。 -
Method Summary
Modifier and TypeMethodDescriptionvoidadd(float value) Add a value to the end of this list.voidaddAll(float... values) Add all values to the end of this list.floataverage()Return the average of all elements.voidclear()Clear this list.booleancontains(float value) Check if this list contains the value.static FloatListcreate()Create an empty FloatList.static FloatListcreate(int initialCapacity) Create a FloatList with initial capacity.booleanvoidforEach(FloatList.FloatConsumer action) Apply action to each element.static FloatListfrom(float[] array) Create a FloatList from a float array.static FloatListfrom(Collection<Float> collection) Create a FloatList from a Collection of Float.floatget(int index) Get the element at the specified index.inthashCode()intindexOf(float value) Return the index of the first occurrence of the value.booleanisEmpty()Check if this list is empty.floatmax()Return the maximum element.floatmin()Return the minimum element.static FloatListof(float... values) Create a FloatList from values.voidreverse()Reverse the order of elements.floatset(int index, float value) Set the element at the specified index.intsize()Return the size of this list.voidsort()Sort the elements in ascending order.subList(int fromIndex, int toIndex) Return a sub-list view as a new FloatList.floatsum()Return the sum of all elements.float[]Return all elements as a float array.toList()Return all elements as a boxed List.toString()
-
Method Details
-
create
Create an empty FloatList. 创建空 FloatList。- Returns:
- new FloatList | 新的 FloatList
-
create
Create a FloatList with initial capacity. 创建指定初始容量的 FloatList。- Parameters:
initialCapacity- initial capacity | 初始容量- Returns:
- new FloatList | 新的 FloatList
- Throws:
IllegalArgumentException- if capacity is negative | 如果容量为负
-
of
Create a FloatList from values. 从值创建 FloatList。- Parameters:
values- the values | 值- Returns:
- new FloatList | 新的 FloatList
-
from
Create a FloatList from a float array. 从 float 数组创建 FloatList。- Parameters:
array- the source array | 源数组- Returns:
- new FloatList | 新的 FloatList
-
from
Create a FloatList from a Collection of Float. 从 Float 集合创建 FloatList。- Parameters:
collection- the source collection | 源集合- Returns:
- new FloatList | 新的 FloatList
- Throws:
NullPointerException- if collection contains null elements | 如果集合包含 null 元素
-
size
public int size()Return the size of this list. 返回此列表的大小。- Returns:
- the size | 大小
-
isEmpty
public boolean isEmpty()Check if this list is empty. 检查此列表是否为空。- Returns:
- true if empty | 如果为空则返回 true
-
get
public float get(int index) Get the element at the specified index. 获取指定索引处的元素。- Parameters:
index- the index | 索引- Returns:
- the element | 元素
- Throws:
IndexOutOfBoundsException- if index is out of range | 如果索引超出范围
-
set
public float set(int index, float value) Set the element at the specified index. 设置指定索引处的元素。- Parameters:
index- the index | 索引value- the new value | 新值- Returns:
- the old value | 旧值
- Throws:
IndexOutOfBoundsException- if index is out of range | 如果索引超出范围
-
add
public void add(float value) Add a value to the end of this list. 向此列表末尾添加值。- Parameters:
value- the value | 值
-
addAll
public void addAll(float... values) Add all values to the end of this list. 向此列表末尾添加所有值。- Parameters:
values- the values | 值
-
clear
public void clear()Clear this list. 清空此列表。 -
contains
public boolean contains(float value) Check if this list contains the value. 检查此列表是否包含该值。- Parameters:
value- the value | 值- Returns:
- true if contains | 如果包含则返回 true
-
indexOf
public int indexOf(float value) Return the index of the first occurrence of the value. 返回值首次出现的索引。- Parameters:
value- the value | 值- Returns:
- the index, or -1 if not found | 索引,未找到则返回 -1
-
sum
public float sum()Return the sum of all elements. 返回所有元素的和。- Returns:
- the sum | 和
-
min
public float min()Return the minimum element. 返回最小元素。- Returns:
- the minimum | 最小值
- Throws:
NoSuchElementException- if empty | 如果为空
-
max
public float max()Return the maximum element. 返回最大元素。- Returns:
- the maximum | 最大值
- Throws:
NoSuchElementException- if empty | 如果为空
-
average
public float average()Return the average of all elements. 返回所有元素的平均值。- Returns:
- the average | 平均值
- Throws:
NoSuchElementException- if empty | 如果为空
-
toFloatArray
public float[] toFloatArray()Return all elements as a float array. 以 float 数组形式返回所有元素。- Returns:
- the float array | float 数组
-
toList
-
sort
public void sort()Sort the elements in ascending order. 按升序排序元素。 -
reverse
public void reverse()Reverse the order of elements. 反转元素顺序。 -
subList
Return a sub-list view as a new FloatList. 返回子列表(新 FloatList)。- Parameters:
fromIndex- start index (inclusive) | 起始索引(包含)toIndex- end index (exclusive) | 结束索引(不包含)- Returns:
- the sub-list | 子列表
- Throws:
IndexOutOfBoundsException- if indices are out of range | 如果索引超出范围
-
forEach
Apply action to each element. 对每个元素应用操作。- Parameters:
action- the action | 操作
-
equals
-
hashCode
-
toString
-