ArrayList: Java Collections Framework Video Tutorial, Part 1

The first part of a series on the Java Collections Framework, an absolutely vital set of classes for organising data in your code. In this part we’ll look at ArrayList; an expandable array. ArrayList is probably the most used and easiest to use member of the collections framework.

After starting the video, click the maximise button to make it fullscreen so you can see the code!

Code For This Tutorial

App.java:

import java.util.ArrayList;
import java.util.List;

public class App {

	public static void main(String[] args) {
		ArrayList<Integer> numbers = new ArrayList<Integer>();

		// Adding
		numbers.add(10);
		numbers.add(100);
		numbers.add(40);

		// Retrieving
		System.out.println(numbers.get(0));

		System.out.println("\nIteration #1: ");
		// Indexed for loop iteration
		for (int i = 0; i < numbers.size(); i++) {
			System.out.println(numbers.get(i));
		}

		// Removing items (careful!)
		numbers.remove(numbers.size() - 1);

		// This is VERY slow
		numbers.remove(0);

		System.out.println("\nIteration #2: ");
		for (Integer value : numbers) {
			System.out.println(value);
		}

		// List interface ...
		List<String> values = new ArrayList<String>();
	}
}

Learn to program Java Swing with my complete video course – desktop programming and applets. Includes 7 free videos. Click here for details.

All pages on this site are copyright © 2013 John W. Purcell

5 Responses to ArrayList: Java Collections Framework Video Tutorial, Part 1

  1. Magesh says:

    The Java Multithreading series is excellent, followed by collection framework is a great idea.

  2. Saravana says:

    Threading Tutorials are excellent!!

  3. suresh says:

    thank u sir…….

  4. suresh says:

    thnak you sir for the nice explanation and codes..

  5. Pranav says:

    Can you add a video for vector and enumeration explanation please?? Thanks

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Posted in Java, Java Collections Framework | Tagged , , , , |