Class LongList

java.lang.Object
cloud.opencode.base.collections.primitive.LongList
All Implemented Interfaces:
Serializable, Iterable<Long>

public final class LongList extends Object implements 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 Details

    • create

      public static LongList create()
      Create an empty LongList. 创建空 LongList。
      Returns:
      new LongList | 新的 LongList
    • create

      public static LongList create(int initialCapacity)
      Create a LongList with initial capacity. 创建指定初始容量的 LongList。
      Parameters:
      initialCapacity - initial capacity | 初始容量
      Returns:
      new LongList | 新的 LongList
    • of

      public static LongList of(long... values)
      Create a LongList from values. 从值创建 LongList。
      Parameters:
      values - the values | 值
      Returns:
      new LongList | 新的 LongList
    • range

      public static LongList range(long start, long end)
      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

      public LongStream stream()
    • sort

      public void sort()
    • reverse

      public void reverse()
    • primitiveIterator

      public PrimitiveIterator.OfLong primitiveIterator()
    • iterator

      public Iterator<Long> iterator()
      Specified by:
      iterator in interface Iterable<Long>
    • forEach

      public void forEach(LongConsumer action)
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object