✨
Java
  • 자바의 역사
  • Ch1
    • Before Start Java
      • History of Java
      • Feature of Java
      • API Documentation
      • Hello World!
      • eclipse shortcut
      • Eclipse IDE
      • GitHub to eclipse
  • Ch2
    • Variable
      • Variable
    • Variable Type
    • Character and String
    • Primitive type and range
    • printf and formatter
    • Scanner
    • Overflow of Int
    • Transition between different variable types
    • Object Array
  • CH3
    • Operator
  • CH4
    • 조건문과 반복문
    • if statement
    • switch
    • Math.random()
    • for statement
    • while statement
    • break, continue, named iterated statement
  • CH5
    • Array
    • 배열 활용
    • String Array
  • OOP
    • Intro
  • Class and Object
  • Make multiple Classes in one file
  • How to use Object
  • Object Array
  • Variable type according to declared location
  • Class Variable and Instance Variable
  • Method
  • Call Stack
  • Parameter
  • Static method(Class method) and Instance method
  • (Method)Overloading
  • Constructor
  • Constructor this()
  • Reference type variable "this"
  • Initialize variable
  • Inheritance
  • Composite
  • Single Inheritance, Object Class
  • (Method)Overriding
  • super, super()
  • package, class path
  • import, static import
  • modifier
  • access modifier
  • Encapsulation
  • Polymorphism
  • reference type transition
  • instanceof operator
  • Parameter polymorphism
  • Multiple object using one array
  • Abstract Class, Abstract Method
  • Creating Abstract Class
  • Interface
  • Interface Polymorphism
  • Interface Pros
  • Default method and static method
  • Inner Class
  • Anonymous Class
  • java.lang package and useful class
    • Object class
    • hashCode(), toString()
    • String class
    • StringBuffer class
    • StringBuilder class
    • Math class
    • Wrapper class
    • Number class
    • String to Number, String to Wrapper class
    • Auto-boxing and (auto)Unboxing
  • Collection Framework
    • Collections framework
    • List, Set, Map Interface
    • List의 removeAll() 과 clear() 비교
    • List Interface - ArrayList
    • How to view Java API source
    • List Interface - LinkedList
    • Stack and Queue
    • Iterator, ListIterator, Enumeration
    • Array
    • Comparator와 Comparable
    • Stack
    • String
    • String + char = String
    • String.toCharArray()
    • BufferedReader / BufferWriter
    • Scanner로 String 입력 - next( )와 nextLine( )
    • 공백없이 2차원배열 데이터 String으로 한번에 한줄씩 입력받기(문자/숫자)
    • 공백을 사이에 두고 빠른 2차원 배열 입출력
    • arr[index++]과 arr[index] index++의 차이
    • int와 long의 차이
    • Untitled
    • 타입 간의 변환
    • Array 와 ArrayList
    • valueOf()
    • Char
    • 변수, 객체 초기화(초기값 설정)
  • error troubleshooting
    • No enclosing instance of type
    • ASCII Code Table
    • java.lang.NumberFormatException
    • No enclosing instance..
  • reference
    • String을 생성하는 2가지 방법과 차이점
    • StackOverflowError(스택, 힙 메모리)
    • swtich-case 반복문
Powered by GitBook
On this page

Was this helpful?

  1. Collection Framework

Stack

다음은 스택이 실제로 사용되는 몇 가지 경우입니다.

  • 운영체제(OS: Operating System) 프로그램에서 사용되는 함수들을 스택 자료형에 저장하여 사용합니다.

  • 컴파일러(Compiler) 수학 기호들을 기계어로 변환시 사용합니다. (괄호 등을 매칭하는 경우)

  • 자바 가상 머신(JVM: Java Virtual Machine) JVM 내에서 메서드가 실행, 종료될 때 스택 프레임을 이용하여 관리합니다.

  • 페이지 뒤로가기

  • 실행 취소

  • 수식 괄호 검사

자바 내부에서 스택은 Vector 클래스를 상속받아 사용한다. Vector 자료구조는 ArrayList와 크게 다르지 않다. 내부 구조는 Object[ ] 배열로 데이터들을 관리하며 전체적인 메서드 구조 또한 많이 유사하다. 다만 차이점은 동기화를 지원하냐 안하냐의 여부인데, ArrayList에서는 동기화를 지원하지 않고, Vectorㅇ에서는 동기화를 지원한다. 그렇다 보니 속도 자체는 ArrayList가 조금 더 빠르지만, Thread safe 하지 않다.

쉽게 생각해서 멀티 스레드 환경에서는 Vector, 아닐 경우는 ArrayList를 쓰는 것이 현명하다.

Stack 인터페이스에 구현된 메서드 살펴보겠다. 몇 가지 자주 사용하는 메서드들은 다음과 같다.

<Stack Interface에 선언된 대표적인 메서드>

메서드

리턴 타입

설명

push(E item)

E

스택 맨 위에 요소 추가

pop( )

E

스택 맨 위 요소 제거, 제거된 요소 반환

peek( )

E

스택 맨 위 요소 제거X 반환

search(Object o)

int

스택의 상단부터 탐색하여 지정된 객체가 있는 요소의 위치 반환. 없을 경우 -1 반환.

size( )

int

현재 스택에 있는 요소 갯수 반환

dear( )

void

모든 요소 제거

empty( )

int

현재 스택엥 요소 존재 X : true, 그 외의 경우 false 반환

자바에서는 Vector 클래스를 상속받다 보니 위의 클래스보다 훨씬 많은 메서드 지원한다.(Vector 클래스에 있는 메서드 + 위에 선언된 메서드)

PreviousComparator와 ComparableNextString

Last updated 4 years ago

Was this helpful?