Generic ArrayList test
/**
* Author: Notus
* Date: 2017-10-10
* Function: Generic ArrayList example.
*/
package com.bugber;
import java.util.ArrayList;
public class GArraylistTest
{
public static void main(String args[])
{
ArrayList<Dog> al = new ArrayList<Dog>();
al.add(new Dog("小黄", 3));
al.add(new Dog("大花", 2));
Dog dog = al.get(0);
System.out.println(dog.getName() + " " + dog.getAge());
}
}
class Dog
{
private String name;
private int age;
public Dog(String name, int age)
{
this.name = name;
this.age = age;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}