Home Tutorial Java Collections Arraylist arraylist declaration in java

 
 

Share on Google+Share on Google+
arraylist declaration in java
Posted on: October 23, 2009 at 12:00 AM
Advertisement
It describes how to use the ArrayList collection in Java Program

  • This class is used to make an fixed sized as well as expandable array. 
  • It allows to add any type of object.
  • It is the implementation of the List interface


Example of Java Arraylist Declaration

import java.util.ArrayList;
import java.util.List;

public class List1 {
    public static void main(String[] args) {
        List list=new ArrayList();
        String names[]={"mac","john","alexender","rock","alex"};
        for (int i = 0; i < names.length; i++) {
        list.add(names[i]);
        }
        for (int i = 0; i < names.length; i++) {
        System.out.println((i+1)+" : "+list.get(i));
        }
    }
}
Output
1 : mac
2 : john
3 : alexender
4 : rock
5 : alex


Advertisement

Related Tags for arraylist declaration in java:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: October 23, 2009

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com