Studyon Minte9.com
Head First (Java)




ArrayList



		// add, remove, size, indexOf, contains
		// iteration
		// Array vs ArrayList

The java Standard Edition ships with hundreds of pre-built classes. Just like your own code except that 
these built-in classes are already compiled.

* Add, Remove

	%java

		package testingapp;
		
		import java.util.ArrayList; 
			// need to import class
		
		public class TestingApp {
		    
		    public static void main(String[] args) {
			
			ArrayList<String> myList = new ArrayList<String>(); 
				// special syntax (Generics)
			
			String x = "a";
			String y = "b";
			
			myList.add(x);
			myList.add(y);
			
				// size
			System.out.println("List size: " + myList.size()); // 2
				// contains
			System.out.println("y exists: " + myList.contains(y)); // true
				// indexOf
			System.out.println("y position: " + myList.indexOf(y)); // 1
				// isEmpty
			System.out.println("List is empty: " + myList.isEmpty()); // false
				// remove
			myList.remove(x);
			System.out.println(myList.contains(x)); // false
		    }
		}


* Iteration

	%java

		ArrayList<String> myList = new ArrayList<String>();
		
		String x = "a";
		String y = "b";
		String z = "c";
		
		myList.add(x);
		myList.add(y);
		
		myList.add(0, z); // add with k
		System.out.println("z index: " + myList.indexOf(z)); // 0
		
		for(String s:myList) {
		    System.out.println(s);
		} 
		    //Output: c, a, b	


* Array vs. ArrayList

	1) Array needs a SIDE (ArrayList don't)

		String[] myList1 = new String[2];
		ArrayList<String> myList2 = new ArrayList<String>();


	2) Array needs an INDEX (ArrayList don't)
	
		myList1[0] = x;
		myList1[1] = x;
		    // ArrayList DON'T
		myList2.add(x); // OR myList2.add(0, x);
		myList2.add(x); // OR myList2.add(1, x);

	3) ArrayList objects are parameterized
        
		... ArrayList<String>


http://docs.oracle.com/javase/6/docs/api/java/util/ArrayList.html