package Chapter6.ShiLi;
public class Dog {
public String Name;
public String Type;
// 带参构造函数
public Dog(String name, String type) {
this.Name = name;
this.Type = type;
}
}
-------------Test----------------------
package Chapter6.ShiLi;
import java.util.*;
public class Test3 {
public static void main(String[] args) {
Dog dog = new Dog("欧欧", "雪纳瑞");
Dog dog2 = new Dog("亚亚", "哈士奇");
Dog dog3 = new Dog("美美", "雪纳瑞");
Dog dog4 = new Dog("菲菲", "雪纳瑞");
LinkedList lis = new LinkedList();
lis.add(dog);
lis.add(dog2);
lis.addLast(dog3); // 尾部添加元素
lis.addFirst(dog4); // 首部添加元素
// 查看集合第一条狗狗的昵称
Dog dogaFirst = (Dog) lis.getFirst(); // 第一个元素
System.out.println("第一条狗狗昵称是:" + dogaFirst.Name + "。");
Dog dogaLast = (Dog) lis.getLast(); // 最后一个元素
System.out.println("最一条狗狗昵称是:" + dogaLast.Name + "。");
System.out.println("共有" + lis.size() + "只狗狗");
}
}