You are on page 1of 5

Dt : 5/7/2022

Execution flow of above program:

==========================================================

Note:

=>when we Use WrapperClass objects and String objects,then

Quick Sort is performed automatically.

=>when we Use User definedClass objects then Merge Sort is

Performed.

=>String Classes and WrapperClasses from the Lib are already


implemented from 'java.lang.Comparable' interface.

============================================================

*imp

2.List<E>:

=>List<E> organizes elements based on index values and can hold

duplicate elements.

=>The following are the implementation classes of List<E>:

(a)ArrayList<E>

(b)LinkedList<E>

(c)Vector<e>

(a)ArrayList<E>:

=>ArrayList<E> organizes elements in sequence and which is

NonSynchronized class.

syntax:

ArrayList<Class_name> al = new ArrayList<Class_name>();

Ex:

DemoList1.java

package maccess;
import java.util.*;
public class DemoList1 {
public static void main(String[] args) {
ArrayList<Integer> al = new ArrayList<Integer>();
for(int i=1;i<=5;i++)
{
al.add(new Integer(i));
}
System.out.println("====Display from List<E>===");
System.out.println(al.toString());
al.add(3,new Integer(500));
System.out.println("====Display from List<E>===");
System.out.println(al.toString());
al.remove(3);
System.out.println("====Display from List<E>===");
System.out.println(al.toString());
Integer ele = al.get(3);//get element from index 3
System.out.println("Ele at index 3 is "+ele);
al.set(3,new Integer(700));
System.out.println("====Display from List<E>===");
System.out.println(al.toString());
System.out.println("index of ele 2:"
+al.indexOf(new Integer(2)));

}
}

o/p:

====Display from List<E>===

[1, 2, 3, 4, 5]

====Display from List<E>===

[1, 2, 3, 500, 4, 5]

====Display from List<E>===

[1, 2, 3, 4, 5]

Ele at index 3 is 4

====Display from List<E>===

[1, 2, 3, 700, 5]

index of ele 2:1

Diagram:
----------------------------------------------------

Limitation of ArrayList<E>:

=>when we perform add operation on ArrayList<E> then the eles

are moved in Backward direction,and if we perform remove operation

on ArrayList<E> then the elements are moved in forward direction.

In this process the execution time is wasted in moving the eles

'forward and backward',and which also degrades the performance of

an application.

=>In realtime ArrayList<E> is used in the applications where we

have less number of add and remove operations.

Note:

=>This limitation of ArrayList<E> can be overcomed using


LinkedList<E>.

==============================================================

You might also like