Files
hello-algo/ko/codes/java/chapter_stack_and_queue/stack.java
T
Yudong Jin 2f561d3d51 feat(ko): add the Korean online edition (#2006)
* feat(ko): add the complete Korean online edition

* Use UTF-8 for Python CI output on Windows

* Remove print-book promotion from the Korean site

* fix(ko): preserve emphasis before Korean particles
2026-10-29 03:46:43 +08:00

41 lines
1.1 KiB
Java

/**
* File: stack.java
* Created Time: 2022-11-25
* Author: krahets ([email protected])
*/
package chapter_stack_and_queue;
import java.util.*;
public class stack {
public static void main(String[] args) {
/* 스택 초기화 */
Stack<Integer> stack = new Stack<>();
/* 스택에 원소 삽입 */
stack.push(1);
stack.push(3);
stack.push(2);
stack.push(5);
stack.push(4);
System.out.println("스택 stack = " + stack);
/* 스택 맨 위 원소 접근 */
int peek = stack.peek();
System.out.println("스택 맨 위 원소 peek = " + peek);
/* 스택에서 원소 꺼내기 */
int pop = stack.pop();
System.out.println("스택에서 꺼낸 원소 pop = " + pop + ", 스택에서 꺼낸 후 stack = " + stack);
/* 스택의 길이 반환 */
int size = stack.size();
System.out.println("스택의 길이 size = " + size);
/* 비어 있는지 판단 */
boolean isEmpty = stack.isEmpty();
System.out.println("스택이 비어 있는가 = " + isEmpty);
}
}