Use linked list to avoid using ArrayList.