Tutorial66.com
@Share Application Development Skill.



Tutorial is tutorial...66 is My Country Code Up to 10 Years EXP for Application Development Role in Thailand.
collapse

Tutorial Category



Topic: Arraylist Example in Java  (Read 233 times)


My Development skill
Java JSP Servlet EJB
Spring Framework
Hibernate Framework
iReport Jasper Report
Apache CXF
PHP Codigniter
Oracle PLSQL
Unix Shell Script
About Me

I am Tao Up to 10 Years EXP for Application Development
Arraylist Example in Java
« on: November 10, 2011, 03:19:29 AM »
Arraylist Example in Java Example code for Java ArrayList
Array is Collection class in package java.util
You can put and get data from ArrayList with index
You can for loop , iterate data from ArrayList like Array

Example Code for Java ArrayList
Code: [Select]
package example.util;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Vector;
public class ArrayListExample {
public void arrayListExample(){
//Create ArrayList Object
ArrayList<String> arrayList=new ArrayList<String>();
//Store and Remove data from ArrayList
arrayList.add("value1");
arrayList.add("value2");
arrayList.add("value3");
arrayList.add("value4");
arrayList.add("value5");
System.out.println("ArrayList Data befor "+arrayList);
String removeValue=arrayList.remove(2);
boolean remove1=arrayList.remove("value1");
boolean remove2=arrayList.remove("value3");

Vector<String> v=new Vector<String>();
v.add("value2");
boolean remove3=arrayList.removeAll(v);

System.out.println("Remove Value "+removeValue);
System.out.println("Remove1 "+remove1);
System.out.println("Remove2 "+remove2);
System.out.println("Remove3 "+remove3);
System.out.println("ArrayList Data after "+arrayList);

System.out.println("-- Example for Get Value from ArrayList --");
System.out.println("Get ArrayList value: "+arrayList.get(0));
System.out.println("Contains ArrayList: "+arrayList.contains("value1"));
System.out.println("Contains ArrayList: "+arrayList.contains("value3"));


System.out.println("-- Example for Iterate list from ArrayList --");
Iterator<String> it=arrayList.iterator();
while(it.hasNext()){
String value=it.next();
System.out.println("List Iterated  Value: "+value);
}
System.out.println("-- Example for Loop from ArrayList --");
for (String temp:arrayList){
System.out.println("For value ArrayList "+temp);
}


}
public static void main (String args[]){
ArrayListExample arryList=new ArrayListExample();
arryList.arrayListExample();
}
}






SimplePortal 2.3.3 © 2008-2010, SimplePortal