package com.itheima;
import java.util.*;
class DuiLie
{
private LinkedList link=new LinkedList();//此句改为private LinkedList link;DuiLie(){ link=new LinkedList();}这两句结果都一样有什么区别那种写法比较好
//
public void myAdd(Object obj)
{
link.add(obj);
}
public Object myGet()
{
return(link.removeLast());
}
public boolean isNyll()
{
return(link.isEmpty());
}
}
public class LinkedListTest {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
DuiLie dl=new DuiLie();
dl.myAdd("java01");
dl.myAdd("java02");
dl.myAdd("java03");
while(!dl.isNyll())
{
System.out.println(dl.myGet());
}
}
}
|
|