람다
-
스트림 생성 (collection , 배열)JAVA/스트림, 컬렉션 프레임워크, 람다 2024. 6. 13. 10:46
▤ 목차" data-ke-type="html">HTML 삽입미리보기할 수 없는 소스 ✔스트림 소개단어의 뜻은 '흐름'이다. 어떤 데이터의 흐름으로 유추해 볼 수 있다. 자바 8버전부터 추가된 컬렉션 요소를 하나씩 참조해서 람다식(함수적 인터페이스)으로 처리할 수 있도록 해주는 반복자를 의미한다.스트림 인터페이스는 컬렉션, 배열.. 등의 저장 요소를 하나씩 참조하여 인터페이스(람다식)을 적용하며 반복 처리가 가능하게 한다.반복자 역할을 한다.(internal iteration 내부 반복을 이용)정렬, 집계, 빅데이터 처리 등도 가능하다.1회용이기에 람다식과 많이 사용한다.내부 반복으로 작업 처리를 진행하며 원본 데이터를 변경하지 않는다.새로운 요소를 추가하는 것은 불가능하다.기존 요소 삭제는 불가능하다.무..
-
람다 표현식(lambda Expression)JAVA/스트림, 컬렉션 프레임워크, 람다 2024. 6. 6. 17:22
▤ 목차">HTML 삽입미리보기할 수 없는 소스 ✔ 람다 표현식java SE 8부터 나온 람다 표현식은 메서드를 하나의 식으로 표현한 것을 말한다.하나의 추상 메서드를 가지고 있는 인터페이스를 가지고 있어야 사용이 가능하다.무명 클래스를 화살표 기호를 사용하여 짧게 줄일 수 있다.(parameter ,,,) -> { body }만약, 람다식이 하나의 메서드를 호출하는 경우 ::으로 표현할 수 있다.1) 클래스 이름 :: 메서드 이름2) 참조변수 :: 메서드 이름가독성이 좋은 쪽으로 선택하자.💻 코드로 보기interface HelloInter { int calcData(int a, int b);}public class MyLambda1 implements HelloInter { @Override ..