![]() Return value - The element at the specified index int indexOf(Object o) Fetches the index of the first occurrence of the specified element o - The element to be identified Boolean contains(Object o) Checks if the list contains the specified element Return value - true if the list contains the element Boolean containsAll(Collection c) Checks if the list contains all the elements in the collection Return value - true if the list contains all the elements Boolean equals(Object o) Compares if the list contains all the specified elements in the exact order Return value - true if object elements match with the list Object getIndex(int index) Retrieves the element at the specified index index - the index at which the element that needs to be retrieved Return value - True void clear() Clears all the elements in the list. If the index already contains element, it is subsequently shifted to the right index - index at which the elements needs to be added Return value - true Boolean addAll(int index, Collection c) Adds a collection of elements at the specified index. If the index already contains an element, it is shifted to the right index- the index at which the element needs to be insertedĮ - the element which needs to be inserted Boolean addAll(Collection c) Adds a collection of specified elements to the list. Return value - True void add(int index, Object e) Adds the element to the specified index. Method Description Parameter Boolean add(Object e) Adds the specified element to the end of list. In addition to the below methods, ArrayList in Java has access to all methods of the List interface. Allows duplicate elements in the list Java ArrayList Methods. ![]() It is easy to access any data from the list based on the index.It is a resizeable dynamic array where we can add, modify or remove elements any time from the list.We can create ArrayList in Java Constructors in the below 3 methods: Constructor Description ArrayList() This creates an empty array list ArrayList(Collection c) This creates an array list with the elements of collection ArrayList(int size) This creates an array list of specific size Java ArrayList Features The ArrayList class extends the AbstractList class and implements the List interface. Where E denotes the element or Object type (Eg: Integer, String, etc) Public class ArrayList extends AbstractList implements List, RandomAccess, Cloneable,Serializable In order to use ArrayList in Java, we must import. Java ArrayList example of user-defined objects.Traverse using Iterator and ListIterator.Print ArrayList in Java – Iterate or navigate through elements.Modifying and Removing an element from ArrayList.Creating ArrayList and add elements and collection.How to initialize an ArrayList in Java?.Java ArrayList Generic and Non-Generic Declaration.
0 Comments
Leave a Reply. |