

Elements in the returned list are also referenced by the invoking object. Returns a list that includes elements from start to end.1 in the invoking list. That is, the indexes of subsequent elements are decremented by one.Īssigns obj to the location specified by index within the invoking list. Removes the element at position index from the invoking list and returns the deleted element. Returns an iterator to the invoking list that begins at the specified index. Returns an iterator to the start of the invoking list. Returns the index of the last instance of obj in the invoking list. Returns the index of the first instance of obj in the invoking list. Returns the object stored at the specified index within the invoking collection. Returns true if the invoking list changes and returns false otherwise. Any pre-existing elements at or beyond the point of insertion are shifted up. Inserts all elements of c into the invoking list at the index passed in the index. Inserts obj into the invoking list at the index passed in the index. Several of the list methods will throw an UnsupportedOperationException if the collection cannot be modified, and a ClassCastException is generated when one object is incompatible with another. In addition to the methods defined by Collection, List defines some of its own, which are summarized in the following table. A class that implements an interface must implement all the methods declared in the interface.The List interface extends Collection and declares the behavior of a collection that stores a sequence of elements.Įlements can be inserted or accessed by their position in the list, using a zero-based index. It provides total abstraction means all the methods in an interface are declared with the empty body, and all the fields are public, static and final by default. It can be used to achieve loose coupling.Īn interface is declared by using the interface keyword.By interface, we can support the functionality of multiple inheritance.

There are mainly three reasons to use interface. In other words, you can say that interfaces can. It is used to achieve abstraction and multiple inheritance in Java. There can be only abstract methods in the Java interface, not method body. The interface in Java is a mechanism to achieve abstraction. It has static constants and abstract methods. Since Java 9, we can have private methods in an interface. An interface in Java is a blueprint of a class. Since Java 8, we can have default and static methods in an interface. It cannot be instantiated just like the abstract class. Java Interface also represents the IS-A relationship. In other words, you can say that interfaces can have abstract methods and variables. Why multiple inheritance is supported in Interface while it is not supported in case of class.Īn interface in Java is a blueprint of a class.
