처음 쓴arraylist로 아날로그 창고 조작

1893 단어 ArrayList
package hashMap;
import java.util.ArrayList;
import d.Student;
/**
 *  ArrayList     
 * @author    
 * @see 2010 8 14 
 */

public class Stack
{
	ArrayList<Student> al=new ArrayList<Student>();
	public Object peek()
	{
		return al.get(0);
	}
	public Object pop()//  
	{
		return al.remove(al.size()-1);
	}
	public void push(Student o)//  
	{
		al.add(o);
	}
	public void clear()//    
	{
		al.clear();
	}
	public boolean isEmpty()//       
	{
		if(al.isEmpty())
		{
			return true;
		}
		else 
		{
			return false;
		}
	}
	public Object getIndex(int i)//         
	{
		return al.get(i);
	}
}

 
package hashMap;
import d.Student;
/**
 *  ArrayList     
 * @author    
 * @see 2010 8 14 
 */
public class StackTest
{
	public static void main(String[] args)
	{
		Stack s1=new Stack();
		s1.push(new Student("  ",200));
		s1.push(new Student("  ",200));
		s1.push(new Student("  ",200));
		s1.push(new Student("  ",200));
		while(!s1.isEmpty())
		{
			System.out.println(s1.pop());//      
		}
		
	}
}

 
package hashMap;
/**
 *  ArrayList     
 * @author    
 * @see 2010 8 14 
 */
public class Student
{
	String name;
	int age;
	public Student(String name,int age)
	{
		this.name=name;
		this.age=age;
	}
	public String toString()
	{
		return "  :" +name+"  :"+age;
	}
}

좋은 웹페이지 즐겨찾기