Stack<E> 컬렉션 클래스

jaegeunsong97·2023년 1월 21일
0
post-thumbnail

2023_1_21_TIL

Stack< E >컬렉션의 특징

  • 스스로 객체 생성 가능
    • 상속구조
      • Stack< E > => Vector< E> => List< E >
  • LIFO구조

Stack< E >의 주요 메소드

public class StackMethod {
    public static void main(String[] args) {
        Stack<Integer> stack = new Stack<>();

        stack.push(2);
        stack.push(5);
        stack.push(3);
        stack.push(7);

        System.out.println(stack.peek());
        System.out.println(stack.size());
        System.out.println();

        System.out.println(stack.search(7));
        System.out.println(stack.search(3));
        System.out.println(stack.search(5));
        System.out.println(stack.search(2));
        System.out.println(stack.search(9));
        System.out.println();

        System.out.println(stack.pop());
        System.out.println(stack.pop());
        System.out.println(stack.pop());
        System.out.println(stack.pop());
        System.out.println();

        System.out.println(stack.empty());
    }
}

참조

https://m.blog.naver.com/PostView.naver?isHttpsRedirect=true&blogId=jaun2014&logNo=220732230304

profile
현재 블로그 : https://jasonsong97.tistory.com/

0개의 댓글