ArrayList Example

import java.util.ArrayList;
import java.util.Collections;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.ListIterator;
import java.util.Vector;
public class ArrayListDemo1 
{
	public static void main(String[] args) 
	{
	//ArrayList al =new ArrayList();
		Vector al =new Vector();
	System.out.println(al.size());
	al.add("Noida");
	al.add("Pune");
	al.add("Kolkata");
	al.add("Chennai");
	al.add("Bangluru");
	al.add("Delhi");
	al.add("Mumbai");	
	al.add(1,"New city");		
	System.out.println(al.size());
	System.out.println(al); // [ aaa,ccc,ssss]
	for(int i=0;i<al.size();i++)
	{
		System.out.print(al.get(i));
	}
	System.out.println("\n");
	// Sorting in array list
	// Collections.sort(al);
    for (String str: al)
      System.out.print(str);
    System.out.print("\n");
 // iterator
	Iterator itr=al.iterator();
	while(itr.hasNext())
	{
		System.out.print(itr.next());
	}
	// list iterator
	ListIterator it1=al.listIterator();
	while(it1.hasNext())
	{
		it1.set("New Value -"+it1.next());	
	}
	ListIterator it2=al.listIterator();
	while(it2.hasNext())
	{
		System.out.println(it2.next());
	}
	Enumeration e1=al.elements();
	while(e1.hasMoreElements())
	{
		System.out.println(e1.nextElement());
	}
	}
}

Download

Collections in Java

ArrayList Example
HashMap Example
HashTable Example
Array Sort
Read Properties File
Get System Properties


Write your Comment

Name :
Email Id : [ We will not publish your email id ]
Your Comment : [ Maximum 200 chars ]
Enter Security code