Class ArrayListUtil

java.lang.Object
org.agrona.collections.ArrayListUtil

public final class ArrayListUtil extends Object
Utility functions for working with ArrayLists.
  • Method Details

    • fastUnorderedRemove

      public static <T> void fastUnorderedRemove(ArrayList<T> list, int index)
      Removes element at index, but instead of copying all elements to the left, moves into the same slot the last element. This avoids the copy costs, but spoils the list order. If index is the last element it is just removed.
      Type Parameters:
      T - element type.
      Parameters:
      list - to be modified.
      index - to be removed.
      Throws:
      IndexOutOfBoundsException - if index is out of bounds.
    • fastUnorderedRemove

      public static <T> void fastUnorderedRemove(ArrayList<T> list, int index, int lastIndex)
      Removes element at index, but instead of copying all elements to the left, moves into the same slot the last element. This avoids the copy costs, but spoils the list order. If index is the last element it is just removed.
      Type Parameters:
      T - element type.
      Parameters:
      list - to be modified.
      index - to be removed.
      lastIndex - last element index in the list to be swapped into the removed index.
      Throws:
      IndexOutOfBoundsException - if index or lastIndex are out of bounds.
    • fastUnorderedRemove

      public static <T> boolean fastUnorderedRemove(ArrayList<T> list, T e)
      Removes element but instead of copying all elements to the left, moves into the same slot the last element. This avoids the copy costs, but spoils the list order. If element is the last element then it is just removed.
      Type Parameters:
      T - element type.
      Parameters:
      list - to be modified.
      e - to be removed.
      Returns:
      true if found and removed, false otherwise.