List_ArrayList_LinkedList1
Objectives:
  • Differences : List does not have clone , ArraysList and LinkedList support Object Clone();

    LinkedList supports Methods LikeaddFirst /addLast , List and ArrayList don't support those methods.
  • Search: 
    • ArrayList relies on  index based operation for its elements as it uses array data structure implicitly which makes it faster for searching an element in the list.
    • On the other side LinkedList relies on  doubly linked list and traverses through all the elements for searching an element, which makes slower than ArrayList.
  • In LinkedList the removal of an element is faster than an ArrayList.
  • Insertion LinkedList is bettern than ArrayList
  • Memory consumption:
    • ArrayList like search a runs with lower memory overhead
  • Both ArrayList and LinkedList are implementation of List interface.

Complete Code:

//
import java.io.*;
import java.lang.reflect.*;
import java.util.*;

public class ClassTemplate1 {

public String str1; private String str2; public ClassTemplate1() {
// TODO Auto-generated constructor stub
str2="encapsulated strictly Private scope";
System.out.println(str2);
}

public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
String[] array1 = {"ABC" ,"ACD", "AEF", "AFG","ADE"};
String[] array2 = {"Peter" ,"Sam", "Adam", "Julia","Nat"};
try{
LinkedList<String> linkedlist = new LinkedList<String>();
/*add(String Element) is used for adding
* the elements to the linked list*/
linkedlist.add("String1");linkedlist.add("String5");
linkedlist.add("String3"); linkedlist.add("String6");
linkedlist.add("String2");
/*Display Linked List Content*/
System.out.println("Linked List Content: as a slab");
System.out.println(linkedlist);
//
System.out.println();
LinkedList<String> linkedlist2 = new LinkedList<String>(Arrays.asList(array2));
Process.display(linkedlist2);
//
System.out.println();
List<String>alist = new ArrayList<String>(Arrays.asList(array1));
Process.display(alist);
}catch(NumberFormatException e){
//
}
}
}
class Process{

Process(){}
public static void display(List<String> str1){

for (Object obj1 :str1)
System.out.print(" " +obj1);
}
}
 

Run time display: