public static long[] toLongArray(LongArrayList longArrayList) {
    long[] longArrayListElements = longArrayList.elements();
    return longArrayListElements.length == longArrayList.size() ? longArrayListElements : longArrayList.toLongArray();
  }
@Test
  public void testToLongArray() {
    // Test empty list
    LongArrayList longArrayList = new LongArrayList();
    long[] longArray = ArrayListUtils.toLongArray(longArrayList);
    assertEquals(longArray.length, 0);

    // Test list with one element
    longArrayList.add(1L);
    longArray = ArrayListUtils.toLongArray(longArrayList);
    assertEquals(longArray.length, 1);
    assertEquals(longArray[0], 1L);

    // Test list with multiple elements
    longArrayList.add(2L);
    longArrayList.add(3L);
    longArray = ArrayListUtils.toLongArray(longArrayList);
    assertEquals(longArray.length, 3);
    assertEquals(longArray[0], 1L);
    assertEquals(longArray[1], 2L);
    assertEquals(longArray[2], 3L);
  }