how to declare an array list of a class

how to declare an array list of a class

Syntax:

List<Class> list = new ArrayList<Class>();
List<Type> list = new ArrayList<Type>();
So‮w:ecru‬ww.lautturi.com

example:

/**
 * @author lautturi.com
 * Java example: declare an array list of class objects in java
 */

import java.util.*;
class Stuff{
	public Stuff(int id, String str) {
		_id=id;
		_name=str;
	}
	int _id;
	public String _name;
	
}

public class Lautturi {

	public static void main(String[] args) {

		List<Stuff> list = new ArrayList<Stuff>();
		for(int i=1;i<6;i++) {
			Stuff s = new Stuff(i,"name"+i);
			list.add(s);
		}
		for(Stuff st : list) {
			System.out.println(st._name);
		}		
		
	}
}
Created Time:2017-09-11 15:12:31  Author:lautturi