ArrayList
is a part of collection framework and is present in java.util
package.
It provides us dynamic arrays.
It may be slower than standard arrays, but can be helpful in programs where intensive manipulation of the arrays is needed.
This statement uses the method of generics, < >
,String
.
ArrayList
provides many methods.
For example,
add(E e)
appends the specified element E
to the end of the list.
contains(Object)
returns true if this list contains the specified element.
get(int index)
returns the element at the specified position in the list.
remove(int index)
removes the element at the specified position in this list.
Shifts any subsequent elements to the left (subtracts one from their indices).
size( )
returns the number of elements in this list, i.e., the size of the list.
toArray(T[ ], a)
returns an array containing all of the elements in this list in proper sequence (from first to last element).
assert
statement in Java.
While executing assertion, it is believed to be true.
If it fails, JVM throws an error named AssertionError
.
split(String regex)
has two variants and splits this string around matches of the given regular expression.
Good things come to those who wait. |