You may have some knowledge about the ArrayList function. This article uses js to implement the ArrayList function and attaches the instance Code. For more information, see
1. Summary of the ArrayList Method
Constructor Summary
ArrayList ()
Create an empty list with an initial capacity of 10.
ArrayList (Collection C)
Construct a list of elements that contain the specified collection. These elements are arranged in the order returned by the collection iterator.
ArrayList (int initialCapacity)
Creates an empty list with the specified initial capacity.
Method Summary
Boolean add (E e)
Add the specified element to the end of the list.
Void add (int index, E element)
Insert the specified element into the specified position in this list.
Boolean addAll (Collection C)
Add all elements in the collection to the end of the list in the order returned by the iterator of the specified collection.
Boolean addAll (int index, Collection C)
Inserts all elements in the specified collection into the list starting from the specified position.
Void clear ()
Remove all elements from this list.
Object clone ()
Returns a superficial copy of The ArrayList instance.
Boolean contains (Object o)
If the list contains the specified element, true is returned.
Void ensureCapacity (int minCapacity)
If necessary, increase the capacity of this ArrayList instance to ensure that it can accommodate at least the number of elements specified by the minimum capacity parameter.
E get (int index)
Returns the element at the specified position in the list.
Int indexOf (Object o)
Returns the index of the specified element that appears for the first time in the list, or-1 if the list does not contain the element.
Boolean isEmpty ()
Returns true if the list contains no elements.
Int lastIndexOf (Object o)
Returns the last index of the specified Element in the list, or-1 if the list does not contain an index.
E remove (int index)
Removes an element from the specified position in the list.
Boolean remove (Object o)
Removes the specified element that appears for the first time in the list (if any ).
Protected void removeRange (int fromIndex, int toIndex)
Remove all elements in the list between fromIndex (included) and toIndex (excluded.
E set (int index, E element)
Replace the specified element with the specified position in the list.
Int size ()
Returns the number of elements in the list.
Object [] toArray ()
Returns an array containing all elements in the list in the appropriate order (from the first to the last element.
T [] toArray (T [])
Returns an array containing all elements in the list in an appropriate order (from the first to the last element). returns the runtime type of the array, which is the runtime type of the specified array.
Void trimToSize ()
Adjust the capacity of the ArrayList instance to the current size of the list.
2. js implementation of some functions