Monday 8 February 2016

What is ArrayList in collection framework

ArrayList:
========
ArrayList is the first implementation class of collection and list interfaces.

1.If we want store group of elements as a single entity then we can go for ArrayList
2.ArrayList is growable in nature
3.Duplicate elements are allowed
4.Insertion order is allowed in ArrayList
5.Homogeneoues objects are allowed
6.Heterogeneous elements are allowed in ArrayList
7.Null insertion is allowed
8.ArrayList implements serializable ,cloneable and RandomAccess interfaces.

Constructors:
===========
1.ArrayList arrayList = new ArrayList();
=============================
Creates an empty arraylist object with default initial capacity 10.
If reaches to its max capacity it is going to create new arraylist object.

2.ArrayList arrayList = new ArrayList(collection c);
======================================
Creates an equivalent araylist object for the specified collection object.

//sample program for arraylist
========================
ArrayListDemo.java:
================

package tesngdemos;

import java.util.ArrayList;
import java.util.HashSet;

public class ArrayListDemo {

    public static void main(String[] args) {

        ArrayList arrayList = new ArrayList();
        arrayList.add(10);
        arrayList.add(10);
        arrayList.add(20);
        arrayList.add(20);
        arrayList.add(30);
        arrayList.add(30);
        arrayList.add('c');
        arrayList.add("selenium by ramesh");
        arrayList.add("selenium by ramesh");
        arrayList.add("rameshat914@gmail.com");
        arrayList.add("selenium by ramesh");
        System.out.println(arrayList);

        HashSet hashSet = new HashSet();
        for (int i = 0; i < arrayList.size(); i++) {
            hashSet.add(arrayList.get(i));
        }
        System.out.println(hashSet);
    }
}
 






No comments:

Post a Comment