Monday, February 16, 2015

ArrayList function

Below are the list of operations that can be performed on the arraylist.

package Example1;

import java.util.ArrayList;
import java.util.Iterator;

public class ArrayList1 {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		ArrayList newarray=new ArrayList();
		newarray.add("John");
		newarray.add("Kevin");
	
	
//	Iterator ite=newarray.iterator();
//		while(ite.hasNext()){
//			System.out.println(ite.next());
//		}
		
//		for(int i=0;i< newarray.size();i++){
//			System.out.println(newarray.get(i));
//		}
		newarray.remove(1);
		newarray.add(1, "Lisa");
		Boolean containsornot=newarray.contains("Lisa");
		for(String i:newarray){
			System.out.println(i);
		}
		System.out.println(containsornot);
		System.out.println(newarray.indexOf("john"));
		System.out.println(newarray.indexOf("John"));
		System.out.println(newarray.isEmpty());
		System.out.println(newarray.set(1, "kevin"));
		for(String i:newarray){
			System.out.println(i);
		}
		System.out.println(newarray.toString());
	}
}


output: Execute this program to view the result >>>
------------------------------------------------------------------------------------------------------------