java.util.ArrayList class
java.util.ArrayList class
- We can store group of objects in ArrayList object.
- Here group of objects means, it can allow us to store same type of objects and different type of objects.
- Same type means, assuming that all objects are in the form of integer types.
- Different type means, assuming that all objects are in the form of integer, float, String, Student and Customer types also.
- ArrayList extends AbstractList class which is a abstract class and implements List interface.
- Size will increase dynamically.
- ArrayList is non synchronized.
- We can get the objects in Random order because ArrayList works on index based.
- The process of ArrayList is very slow, if you are inserting and removing the objects from middle of the ArrayList.
- We will get the output according to insertion order.
- Allows duplicate objects.
--------------------------------------------------------------------------------------------
Program : Example on ArrayList class
Program name : ALDemo1.java
Output :
[1, Nireekshan, A, 1.1, 1.12345]
import java.util.ArrayList;
class ALDemo1
{
public static void main(String args[])
{
ArrayList arrayList = new ArrayList();
arrayList.add(1);
arrayList.add("Nireekshan");
arrayList.add('A');
arrayList.add(1.1f);
arrayList.add(1.12345);
System.out.println(arrayList);
}
}
class ALDemo1
{
public static void main(String args[])
{
ArrayList arrayList = new ArrayList();
arrayList.add(1);
arrayList.add("Nireekshan");
arrayList.add('A');
arrayList.add(1.1f);
arrayList.add(1.12345);
System.out.println(arrayList);
}
}
Compile : javac ALDemo1.java
Run : java ALDemo1
Output :
[1, Nireekshan, A, 1.1, 1.12345]
--------------------------------------------------------------------------------------------
Thanks for your time.
- Nireekshan