Skip to main content

Posts

Showing posts from December, 2018

List Interface of JAVA 8

List Interface List Interface is the subinterface of Collection. It contains index-based methods to insert and delete elements. It is a factory of ListIterator interface. Lists may contain duplicate elements. The Java platform contains two general-purpose List implementations. ArrayList , which is usually the better-performing implementation, and LinkedList which offers better performance under certain circumstances. List interface includes different operations: #       Query Operations #      Modification Operations #      Bulk Modification Operations #      Comparison and hashing #      Positional Access Operations #      Search Operations #      List Iterators #      view Let’s see the List Interface from java.util pacjage: package java.util; import java.util.function.UnaryOperator; public interface List <E> extends Collection <E> {     // Query Operations     int size();   /**Returns the number of elements in this list. *

Iterators in java 8

An  Iterator  is an object that enables you to navigate through a collection and to remove elements from the collection selectively, if desired. You get an Iterator for a collection by calling its iterator method. The following is the Iterator interface . public interface Iterator<E> {     boolean hasNext();     E next();     void remove(); //optional } The  hasNext()  method returns  true  if the iteration has more elements, and the  next()  method returns the next element in the iteration.   The  remove()  method removes the last element that was returned by  next  from the underlying  Collection . The  remove  method may be called only once per call to  next  and throws an exception if this rule is violated. [ Note :  Iterator.remove  is the  only  safe way to modify a collection during iteration; the behavior is unspecified if the underlying collection is modified in any other way while the iteration is in progress.] Use  Iterator  instead of t