arraylist in java arraylist example in java arraylist in java example using arraylist in java example of arraylist in java sorting arraylist in java arraylist examples in java methods in arraylist in java default size of arraylist in java declaring arraylist in java arraylist program in java list and arraylist in java creating arraylist in java difference between vector and arraylist in java difference between array and arraylist in java difference between arraylist and linkedlist
ArrayList:
1) Arraylist is one of the buttom most concrete sub
class of 1 – D collection frame work of abstract
class
2) In arraylist the data is organizing in the form
of cells
3) Creating arraylist is nothing but arraylist class
ArrayList al=new ArrayList();
Methods of ArrayList :
1)
public void addFirst(object):
This method is used for inserting an object into any collection frame
work variable at
first of the Linked list object.
2)
public void addLast(object) :
This method is used for inserting an object into any collection frame
work variable at
last of the Linked List object.
3)
public
object getFirst():
This method is used for retrieving the object from any collection frame
work variable at
first of any Linked List.
4)
public
object getLast():
This method is used for retrieving the object from any collection frame
work variable at
last of any Linked List.
Difference
Between Arraylist and LinkedList Advantages of Array List Over Linked
List:
1)
ArrayList less memory
space because cell address are stored in associative memory and
it will take very
less space, Retrieving the data from
array list takes less amount of time
because retrieving the address of call
from associative memory is taking less time
2)
Linkedlist takes more
memory space because both data and address part of the nodes are collectively
storing in heap memory. Due to more memory space performance of an
application may be reduced. Retrieving the data from linked list will take more
amount of time because after processing the current node value, before processing the next node value jvm
explicitly retrieves address of next node from address part of current node.
Difference
Between ArrayList and Vector class :
The
functionality of vector class object is more or less similar to ArrayList
class. But vector object class belongs
to synchronized and ArrayList class object belongs to non – synchronized.
Difference Between ArrayList and Array :
The size of arraylist is dynamic in nature and it allows to store
the both homogeneous and heterogeneous elements. The size of Array is fixed and
it allows to store only homogeneous values.
The Following Program Illustrate the concept of
ArrayList
import java.util.*;
Class Arrylistdemo
{
Public static void main(String
args[])
{
ArrayList al=new ArrayList();
System.out.println(“Content of al=”+al);
System.out.println(“is linked list
empty =”+al.isEmpty());
System.out.println(“Size of ll=”+al.size());
//add the data to LinkedList Object al
al.add(new Integer(20));
al.add(new Integer(30));
al.add(new Integer(40));
System.out.println(“Content of al”+al);//[20,30,40]
System.out.println(“is LinkedList empty
?”+al.isEmpty());//false
// add the element 5 to Linked list at
first
al.addFirst(new Integer(10));
//add the element 50 to Linked List at
Last
al.addLast(new Integer(50));
System.out.println(“Content of al=”+al);
System.out.println(“Size of al=”+al.size());
//Extracting the data from Linked List
System.out.println(“Extracting the data
from linked list object al by using iterator”);
Iterator itr=al.iterator();
int s=0;
for( ;itr.hasNext(); )
{
Object obj=itr.next();
Integer io=(Integer)obj;
int
x=io.intValue();
System.out.println(x);
s=s+x;
}
ListIterator litr=al.listiterator();
While(litr.hasNext())
{
Object obj1=litr.next();
System.out.println(obj1);
}
System.out.println(“Extracting the data
from Linked list by using List iterator”);
While(litr.hasPrevious())
{
object obj2=litr.Previous();
object obj2=litr.Previous();
Integer
io1=(Integer)obj2;
int x1=io1.intValue();
System.out.println(x1);
}
}
}
}
Data Extraction Interfaces:
1- D and 2-D Collection Frame work classes are
To read the values dynamically from keyboard their is a class.
The above given methods should be of Linked List not Array List.
ReplyDelete