class
ArrayList<E> is an array (in other words, a collection of elements).
Any element can be gotten by integer index.
You can add and remove elements using the
add,
remove functions.
Note!
There is NO class
ArrayList <E>in the
Kotlin library
Kotlin The library contains only the title. This name references the
Java library.
Kotlin
TypeAliases.kt file
typealias class ArrayList<E> = java.util.ArrayList<E>
Description:
Java
Library java.util file ArrayList.java
class ArrayList<E> extends AbstractList<E>
implements List<E>,
RandomAccess,
Cloneable,
Serializable
{
Hide Functions << ...
Let's look at Functions >> ...
// Constructors
ArrayList()
ArrayList(Collection<? extends E> c)
ArrayList(int initialCapacity)
// Methods
boolean add(E e)
void add(int index, E element)
boolean addAll(Collection<? extends E> c)
boolean addAll(int index, Collection<? extends E> c)
void clear()
Object clone()
boolean contains(Object o)
void ensureCapacity(int minCapacity)
void forEach(Consumer<? super E> action)
E get(int index)
int indexOf(Object o)
boolean isEmpty()
Iterator<E> iterator()
int lastIndexOf(Object o)
ListIterator<E> listIterator()
ListIterator<E> listIterator(int index)
E remove(int index)
boolean remove(Object o)
boolean removeAll(Collection<?> c)
boolean removeIf(Predicate<? super E> filter)
void removeRange(int fromIndex, int toIndex)
void replaceAll(UnaryOperator<E> operator)
boolean retainAll(Collection<?> c)
E set(int index, E element)
int size()
void sort(Comparator<? super E> c)
Spliterator<E> spliterator()
List<E> subList(int fromIndex, int toIndex)
Object[] toArray()
<T> T[] toArray(T[] a)
void trimToSize()
// Methods inherited from class java.util.AbstractList
boolean equals(Object o)
int hashCode()
// Methods inherited from class java.util.AbstractCollection
boolean containsAll(Collection<?> c)
String toString()
// Methods inherited from class java.lang.Object
void finalize()
Class<?> getClass()
void notify()
void notifyAll()
void wait()
void wait(long timeout)
void wait(long timeout, int nanos)
// Methods inherited from interface java.util.List
boolean containsAll(Collection<?> c)
boolean equals(Object o)
int hashCode()
// Methods inherited from interface java.util.Collection
Stream<E> parallelStream()
Stream<E> stream()
}
To create
ArrayList<E>, use the function:
arrayListOf(...)
Kotlin
Method 1
val allCars:ArrayList<Car> = arrayListOf(
Car("Audi A6", 50000),
Car("Toyota Camry", 25000),
Car("Honda Accord", 40000)
)
Another way to create we can use constructor
ArrayList:
Kotlin
Method 2
val allCars:ArrayList<Car> = ArrayList<Car>(
listOf(
Car("Audi A6", 50000),
Car("Toyota Camry", 25000),
Car("Honda Accord", 40000)
)
)