Java List Interface

  • List interface inwards coffee is ordered collection then it tin plough over notice shop elements inwards sequence.
  • List interface is sub interface together with it extends to Collection interface.
  • List interface tin plough over notice concur duplicate elements then you lot tin plough over notice insert duplicate elements too.
  • You tin plough over notice access elements from listing yesteryear integer index.
  • Collection framework has many interfaces inwards coffee together with listing interface is i of them.
  • List interface provides ListIterator to traverse through elements listing inwards backward together with frontward directions.
List interface java


Few to a greater extent than frequently than non used methods inwards listing interface are every bit bellow.
  • void add(int index,Object element) : It volition insert chemical cistron at specified index seat inwards list.
  • boolean addAll(int index,Collection c) : It volition add together all elements of given collection inwards to the listing at specified index position.
  • object get(int Index ) : It volition render object at specified index seat from list.
  • object set(int index,Object element) : It volition assign object at specified index seat inwards list.
  • object remove(int index) : It volition take away object from specified position.
  • ListIterator listIterator() : It volition returns the listing iterator at start of invoking list.
  • ListIterator listIterator(int x) : It volition returns the listing iterator at specified index seat inwards list.
  • int indexOf(Object obj) : It volition render index of start event of object from invoking list.
  • int lastIndexOf(Object obj) : It volition render index of terminal event of object from invoking list.
List interface is implemented yesteryear many classes similar Arraylist, Linkedlist together with Vector.  Here, I convey represented representative of listing interface using few methods from dissimilar cast implementation.

package JAVAExamples;  import java.util.ArrayList; import java.util.LinkedList; import java.util.List; import java.util.ListIterator;  world cast InterfaceList {   world static void main(String[] args) {   // Add elements inwards ArrayList.   List al = novel ArrayList();   al.add("New York");   al.add("Delhi");   al.add("Tokyo");      // Print arraylist elements.   System.out.println("ArrayList Elements");   System.out.print(al);   System.out.println();    // Add elements inwards linkedlist.   List ll = novel LinkedList();   ll.add("New York");   ll.add("Delhi");   ll.add("Tokyo");      // Print linkedlist elements.   System.out.println();   System.out.println("LinkedList Elements");   System.out.print(ll);   System.out.println();    // Get together with impress arraylist's tertiary element.   System.out.println();   System.out.println("Element at tertiary seat inwards arralist is : " + al.get(2));    // Using ListIterator to traverse through frontward together with backward directions inwards arralist.   ListIterator<String> itrtr = al.listIterator();    // Traverse inwards frontward direction.   System.out.println();   System.out.println("Traversing through arralist elements inwards frontward direction...");   piece (itrtr.hasNext()) {    System.out.println(itrtr.next());   }    // Traverse inwards backward direction.   System.out.println();   System.out.println("Traversing through arralist elements inwards backward direction...");   piece (itrtr.hasPrevious()) {    System.out.println(itrtr.previous());   }  } }

Output
ArrayList Elements [New York, Delhi, Tokyo]  LinkedList Elements [New York, Delhi, Tokyo]  Element at tertiary seat inwards arralist is : Tokyo  Traversing through arralist elements inwards frontward direction... New York Delhi Tokyo  Traversing through arralist elements inwards backward direction... Tokyo Delhi New York

In to a higher house representative you lot tin plough over notice meet how arralist, linkedlist, become method together with listiterator works.

More interesting articles here :Generation Enggelmundus Internet Marketing Tool here :Zeageat IM http://www.software-testing-tutorials-automation.com/

1 Comments

  1. I would say while reading your article, i felt very proud. Because the information you written very useful, please keep posting this type of articles. If you guys looking for a Advanced Java Training in Bangalore. please click below link.

    ReplyDelete
Post a Comment
Previous Post Next Post