Ads Sponsored By Google :)

Monday, 21 January 2013

List interface methods in java|6|collection|api with example|Collections|document|java.util.List

List interface in java List interface in java with example List interface in Collection List interface in java Collections List interface in java api List interface in java methods java 6 api list interface List interface api java api document interface list List interface methods methods of the java.util.list interface

    List Interface :
          List is one of the sub interface of collection interface. An object of list interface also 
   allows duplicate elements. it is allows us to organize the data either at the beginning or 
   at the last or in the middle. It displays the data in sorted order. It allows to retrieve the 
   data in both forward and back direction.

    Methods in List interface :

            As we already know List is  sub interface of collection interface, so that all the 
    methods of collection inherited into List.
     Methods in Collection that are inherited into List. They are

a)      Public int size()
b)      Public Boolean isEmpty()
c)       Pubic Boolean add(object)
d)      Public Boolean addAll(Collection)
e)      Public Iterator iterator()

To know in about above methods, then it is necessary to refer Collection Interface.

1)      Public void add(int,Object) :
    This method is used for adding an element to any collection frame work variable either in the beginning  or in the middle or at the last. (i.e dynamic insertion can be possible).

For Example :
       List l is an object of List interface contains 20, 23.45, ‘k’
       l.add(2,new Float(19.4f));                                0      1        2
       System.out.println(l);// 20, 23.45, 19.4, ‘k’
2)      Public object get(int) :
    This method is used for obtaining the value from the collection frame work variable by passing position.
For Example :
       Consider List l is an object contains elements as 10, 20.56,  ’a’, ”javajavax”
                         Object obj1=l.get(1);                                                       0      1         2          3
                        Object obj2 =l.get(5);                    

3)      Public object remove(int) :
         This method is used for removing the elements of any collection frame work variable based on the position.

4)      Public void remove(object) :
         This method is used for removing the content of any collection frame work variable.
While we are removing string related, jvm will remove first occurrence provided the content must be matched with same meaning and case.

5)      Public void removeAll()  :
       This method is used for removing all the elements of any collection frame work.

6)      Public ListIterator ListIterator() :
          This method is used for retrieving all entries of any collection frame variable and forms like bi directional chain. This method returns an object of ListIterator interface.
  List iterator interface object is by default pointing just before the first element of any collection frame work variable like Iterator interface object.
       To know about ListIterator() first of all to know about ListIterator interface.

The Following diagram illustrate the hierarchy of Abstract classes of 1-D Collection
Frame work

Collection Frame work Abstract & concrete classes

Data Extraction Interfaces:

          1- D and 2-D Collection Frame work classes are 
               To read the values dynamically from keyboard their is a class.
                     Java.util.Scanner or Scanner class

No comments:

Post a Comment