Git Product home page Git Product logo

Comments (1)

polarHub25 avatar polarHub25 commented on September 4, 2024

스트림 vs 컬렉션

  1. 스트림

    • 데이터를 처리하는 API
    • 일회성 , 한번 사용 후 재사용 불가
    • 지연 평가
    • 내부 반복
    • parallerStream()을 통해 간단히 병렬 처리 가능
    • 필터링, 매핑, 집계 등 데이터 처리 중심 함수 제공
    • 순차 접근과 병렬 접근 가능
  2. 컬렉션

  • 데이터를 저장하고 관리하는 자료구조
  • 여러번 데이터를 반복하며 재사용 가능
  • 즉시 평가
  • 외부반복
  • 순차처리
  • 데이터 추가, 삭제 , 사이즈 확인, 포함 여부 확인
  • 순차 접근
// 데이터 예시
List<String> names = Arrays.asList("Alice", "Bob", "Charlie", "David");

// 컬렉션을 사용한 연산
List<String> filteredNames = new ArrayList<>();
for (String name : names) {
    if (name.length() > 3) { // 필터링 조건
        filteredNames.add(name.toUpperCase()); // 변환
    }
}
System.out.println(filteredNames); // 출력: [ALICE, CHARLIE, DAVID]

// 스트림을 사용한 연산
List<String> streamResult = names.stream()
    .filter(name -> name.length() > 3) // 필터링 조건
    .map(String::toUpperCase)          // 변환
    .collect(Collectors.toList());     // 결과 수집
System.out.println(streamResult);      // 출력: [ALICE, CHARLIE, DAVID]

내부반복 vs 외부반복

  1. 외부반복
  • 개발자가 직접 반복문을 사용하여 컬렉션의 요소를 순회하는 방법.
  • 순서와 제어는 개발자가 직접 담당
  1. 내부반복
  • 자바의 Stream Api, 컬렉션 foreach 처럼 반복의 제어권을 라이브러리에 맡기고, 처리할 작업만 정의 하는 방법.
  • 개발자는 처리할 작업만 정의

from studylog.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.