Java-35-ArrayList methods in Java || Java Programming Tutorial

154 Просмотры
Издатель
Methods in ArrayList
Frequently used methods in ArrayList are-
boolean add(Element e)- Used to add Element e at the end of the list.
void add(int index, Element e)- adds Element e at specified index.
boolean addAll(Collection c)- adds all the elements of Collection c at the end of the List.
boolean addAll(int index, Collection c)- appends elements of collection c after specified index in the list.
set(int index, Element e)- Replaces element at index position with the given Element e.
int size()- Returns the size or number of elements present in the ArrayList.
trimToSize()- Trims down ArrayList capacity to current size of the list.
void ensureCapacity(int cap)- Manually increases capacity of ArrayList with specified cap.
get(int index)- Returns the element at index position of the ArrayList.
boolean contains(Element e)- Returns true if specified element is present in the ArrayList.
List subList(int from, int to)- Returns a sublist containing the elements in between the index positions from and to.
array[] toArray()- Returns array[] containing all elements of the ArrayList.
int indexOf(Element e)- Returns the index position of Element e where it is first located in the ArrayList. If not present returns -1.
int lastIndexOf(Element e)- Returns the index position of the specified element where it is last located in the ArrayList. If not present returns -1.
remove(int index)- Removes the element from the index position specified.
remove(Element e)- Removes Element e where it is first located in the ArrayList.
removeAll(Collection c)- Removes all the elements that are in Collection c , from the ArrayList.
removeRange(int from, int to)- Removes all the elements in between the index ranges.
boolean isEmpty()- Returns true if the ArrayList is empty else returns false.
void clear()- Used to remove all the elements from the ArrayList.

Hey ! Thanks for watching my video..
for more you can also visit my -

twitter: https://twitter.com/rapid_tutor

facebook: https://www.facebook.com/RapidTutor-106765660738888/

Keep Learning Keep Growing with Rapid Tutor..
#ArrayListMethods #ArrayList #JavaTutorial
Категория
Язык программирования Java
Комментариев нет.