Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- My Main:
- package arraylist;
- import java.util.Scanner;
- /**
- *
- * @author dghelardini
- */
- public class ArrayList {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args)
- {
- Scanner userIn = new Scanner(System.in);
- System.out.print("Enter five names: ");
- }
- }
- MyStack Class:
- package arraylist;
- /**
- *
- * @author dghelardini
- */
- public class MyStack extends ArrayList
- {
- private ArrayList<Object> theList = new ArrayList<>();
- public boolean isEmpty()
- {
- return theList.isEmpty();
- }
- public int getSize()
- {
- return theList.size();
- }
- public Object peek()
- {
- return theList.get(getSize()-1);
- }
- public Object pop()
- {
- Object o = theList.get(getSize()-1);
- theList.remove(getSize()-1);
- return o;
- }
- public void push(Object o)
- {
- theList.add(o);
- }
- @Override
- public String toString()
- {
- return "stack:" + theList.toString();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement