![]() List subList(int fromIndex, int toIndex): Returns a view of the portion of this list between the specified fromIndex, inclusive, and toIndex, exclusive.ListIterator listIterator(): Returns a list iterator over the elements in the list.E set(int index, E element): Replaces the element at the specified position in the list with the specified element.E get(int index): Returns the element at the specified position in the list.void clear(): Removes all the elements from the list.boolean retainAll(Collection c): Retains only the elements in this list that are contained in the specified collection.boolean remove(Object o): Removes the first occurrence of the specified element from this list.boolean add(E e): Appends the specified element to the end of this list.Object toArray(): Returns an array containing all of the elements in this list in proper sequence.Iterator iterator(): Returns an iterator over the elements in this list in proper sequence.boolean contains(Object o): Returns true if this list contains the specified element. ![]() boolean isEmpty(): to check if list is empty or not.int size(): to get the number of elements in the list.Some of the useful Java List methods are AbstractList provides a skeletal implementation of the List interface to reduce the effort in implementing List. Some of the most used List implementation classes are ArrayList, LinkedList, Vector, Stack, CopyOnWriteArrayList. Collection interface externs Iterable interface. Java List interface extends Collection interface. Using Generics with List will avoid ClassCastException at runtime. List supports Generics and we should use it whenever possible.List indexes start from 0, just like arrays.List interface got many default methods in Java 8, for example replaceAll, sort and spliterator.List allows you to have ‘null’ elements.List allows you to add duplicate elements.Java List interface is a member of the Java Collections Framework.Some of the important points about Java List are You can access elements by their index and also search elements in the list. ![]() Java List provides control over the position where you can insert an element. Java List is an interface that extends Collection interface. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |