// Arup Guha
// 11/21/2015
// Written in Junior Knights to illustrate ArrayList use.

import java.util.*;

public class TestArrayList {

	public static void main(String[] args) {

		// Create and add some objects.
		ArrayList<String> myObjects = new ArrayList<String>();
		myObjects.add("Skateboard");
		myObjects.add("Juice");
		myObjects.add("Homework");
		System.out.println(myObjects);
		myObjects.add(0, "Money");
		System.out.println(myObjects);
		myObjects.add(2, "TacoBellChickenBurrito");
		System.out.println(myObjects);
		myObjects.add(5, "MillionDollars");
		System.out.println(myObjects);

		// Create a second list and add some objects.
		ArrayList<String> myFood = new ArrayList<String>();
		myFood.add("Spinach");
		myFood.add("Burger");
		System.out.println(myObjects);
		System.out.println(myFood);

		// Retrieve an object.
		String myItem = myObjects.get(3);
		System.out.println(myItem);

		// Remove an object.
		System.out.println("Just removed "+myObjects.remove(3)+".");
		System.out.println(myObjects);

		// Another way to remove an object.
		boolean ans = myObjects.remove("Table");
		System.out.println("Table removed : "+ans);
		ans = myObjects.remove("Skateboard");
		System.out.println(myObjects);

		// And how to replace an object.
		myObjects.set(2, "Billiondollars!!!");
		System.out.println(myObjects);

		System.out.println("I have "+myObjects.size()+" objects.");

		// Counts alll items that are 6 letter or longer.
		int count = 0;
		for (int i=0; i<myObjects.size(); i++) {
			if (myObjects.get(i).length() >= 6)
				count++;
		}
		System.out.println("You have "+count+" items 6 letters or longer.");

		// Counts the number of strings that start with a capital M.
		int countM = 0;
		for (String s: myObjects) {
			if (s.charAt(0) == 'M')
				countM++;
		}
		System.out.println("You have "+countM+" items that start with M.");

	}
}