import java.util.*; public class S { public static void main(String args[]) { Stack<Integer> s = new Stack<Integer>(); //push for(int i = 0; i < 10; i++) System.out.printf("%4d", s.push(i)); System.out.println(); //toString System.out.println(s); //search System.out.printf("Search: %d%n", s.search(5)); //peek System.out.printf("Peer: %d%n", s.peek()); //empty and pop while(!s.empty()) { System.out.printf("%4d", s.pop()); } System.out.println(); } }
import java.util.*; public class S { public static void main(String args[]) { Stack<Integer> s = new Stack<Integer>(); //push for(int i = 0; i < 10; i++) System.out.printf("%4d", s.push(i)); System.out.println(); Enumeration e = s.elements(); while(e.hasMoreElements()) { System.out.printf("%4d", e.nextElement()); } System.out.println(); } }
import java.util.*; public class S { public static void main(String args[]) { Stack<Integer> s = new Stack<Integer>(); //push for(int i = 0; i < 10; i++) System.out.printf("%4d", s.push(i)); System.out.println(); Iterator itr = s.iterator(); while(itr.hasNext()) { System.out.printf("%4d", itr.next()); } System.out.println(); //remove itr = s.iterator(); while(itr.hasNext()) { if((Integer)itr.next()%2 == 0) itr.remove(); } System.out.println(s); } }
import java.util.*; public class S { public static void main(String args[]) { Stack<Integer> s = new Stack<Integer>(); for(int i = 0; i < 10; i++) s.add(i); System.out.println(s); for(int e : s) System.out.printf("%4d", e); System.out.println(); } }