마지막에 저장한 데이터를 가장 먼저 꺼내는 자료구조.
stack 살펴보기
Stack<Innteger> stack = new Stack<>();
stack.push(item: 1);
stack.push(item: 3);
stack.push(item: 7);
stack.push(item: 5);
System.out.println(stack);
[1, 3, 7, 5]
맨 위에거 하나 확인하기 .peek
Stack<Innteger> stack = new Stack<>();
stack.push(item: 1);
stack.push(item: 3);
stack.push(item: 7);
stack.push(item: 5);
System.out.println(stack);
System.out.println(stack.peek);
5
맨위에서 삭제하기 .pop
Stack<Innteger> stack = new Stack<>();
stack.push(item: 1);
stack.push(item: 3);
stack.push(item: 7);
stack.push(item: 5);
System.out.println(stack);
System.out.println(stack.peek);
System.out.println(stack.pop);
5
다른점은 각각 아래에 System.out.println(stack.size);로 확인해 봤을 때,
stack의 empty 함수
Stack<Innteger> stack = new Stack<>();
stack.push(item: 1);
stack.push(item: 3);
stack.push(item: 7);
stack.push(item: 5);
System.out.println(stack);
System.out.println(stack.empty);
//여기까지만 쓰면 값이 남아있으므로 fasle
stack.clear
System.out.println(stack.isEmpty);
true