언어, 알고리즘 공부/Java

자바 스택(Stack) 클래스 사용 방법

쿠몬e 2021. 12. 2. 15:10
import java.util.Stack;
Stack<Integer> stack = new Stack<>();
Stack<String> stack = new Stack<>();


//값 추가
Stack<Integer> stack = new Stack<>();
stack.push(1);
stack.push(2);
stack.push(3);
stack.push(4);


//값 제거
stack.pop();

//전체 값 제거
stack.clear();

//스택 크기 출력
stack.size();

//스택에 요소가 있는지 확인
stack.contains(1);

//스택이 비어있는지 확인
stack.empty();
반응형