단서해
개발일지
단서해
전체 방문자
오늘
어제
  • 분류 전체보기 (29)
    • Project (5)
    • JAVA (2)
    • Server (11)
      • Info (4)
      • 작동 원리 예상 (4)
      • Question (1)
      • JPA (1)
    • Infra (2)
    • Trouble Shooting (8)

블로그 메뉴

  • 홈
  • 글쓰기
  • 관리

공지사항

인기 글

태그

  • yml
  • 트랜잭션
  • Github Actions
  • 파일 경로
  • 동시성
  • gradle-wrapper.properties
  • CodeDeploy
  • Intellij
  • error
  • enhanced for
  • flutter
  • gradlew
  • thymeleaf
  • JPA
  • Fileter
  • @configuration
  • Reflection
  • 분산락
  • REQUIRES_NEW
  • Java
  • pinpoint
  • gradle
  • @Component scan
  • 비동기
  • docker
  • OAuth2.0
  • 성능 개선
  • 무중단 배포
  • Spring
  • Lettuce

최근 댓글

최근 글

티스토리

hELLO · Designed By 정상우.
단서해

개발일지

JAVA

[Java] Enhanced for문 로직

2022. 7. 29. 21:44

아래 예시처럼 Enhanced for문의 경우, 위의 문장에서 아래의 문장으로 번역된다.

 

Enhanced for문 내부구조

https://docs.oracle.com/javase/specs/jls/se8/html/jls-14.html#jls-14.14.2

 

Chapter 14. Blocks and Statements

In the following example, a mathematical graph is represented by an array of arrays. A graph consists of a set of nodes and a set of edges; each edge is an arrow that points from some node to some other node, or from a node to itself. In this example it is

docs.oracle.com

 

그렇기에 list 같이 요소 접근에 O(n)의 시간복잡도를 가지는 자료구조를 for loop에서 이용할 때,

 

Enhanced for문을 사용하면 상수 시간으로 효율적인 접근이 가능해진다.

 

하지만, array 같은 자료구조를 사용할 때는 불필요한 연산이 늘어나 오히려 비효율적일 수 있다.

 

 

 

 

 

잘못된 내용에 대한 수정이나, 본문에 대한 어떠한 피드백도 환영하니 댓글로 남겨주시면 감사하겠습니다. ㅎ

'JAVA' 카테고리의 다른 글

[Java] Reflection 사용 시 주의점.  (0) 2022.08.28
    'JAVA' 카테고리의 다른 글
    • [Java] Reflection 사용 시 주의점.
    단서해
    단서해

    티스토리툴바