java

[Java] Stack Class

kjh42447 2022. 7. 25. 16:26

자바에서 Stack은 Java.util.Vector클래스를 상속받아 이미 구현되어있다.

주요 메소드및 사용법은 다음과 같다.

 

  • E push(E item) : item을 스택에 집어넣는다.
  • E pop() : 스택 최상단의 값을 꺼내서 리턴한다.
  • E peek() : 스택 최상단의 값을 꺼내지 않고 리턴한다.
  • boolean empty() : 스택이 비어있는지 확인한다.
  • int search(Object o) : o가 있으면 스택의 가장 높은 곳에 있는 o의 인덱스를 반환한다. 없을 경우 -1을 반환한다.

 

참고 문서

https://docs.oracle.com/javase/7/docs/api/java/util/Stack.html

 

Stack (Java Platform SE 7 )

The Stack class represents a last-in-first-out (LIFO) stack of objects. It extends class Vector with five operations that allow a vector to be treated as a stack. The usual push and pop operations are provided, as well as a method to peek at the top item o

docs.oracle.com

 

'java' 카테고리의 다른 글

[Java] java.lang.StackOverflowError: null  (0) 2022.11.17
[Java] ArrayList<String[]> 정렬  (0) 2022.07.30
[Java] 스트림(Stream)  (0) 2022.07.18
[Java] 자바 람다(Java Lambda)  (0) 2022.07.18
[Java] 애너테이션(Annotation)  (0) 2022.07.18