Contents
설명람다 표현식은 리스트의 요소를 조건에 맞게 필터링할 때도 유용하다.
package ex07.ch02;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class Beh03 {
public static void main(String[] args) {
// String s = "hello";
// System.out.println(s.startsWith("h")); // h로 시작하니 ? boolean으로 리턴
List<String> word = new ArrayList<>();
word.add("apple");
word.add("banana");
word.add("cherry");
word.removeIf(s -> s.contains("a")); // 괄호 안에서 ctrl + space 해서 보자 !
System.out.println(word);
}
}

설명
removeIf()
는 리스트에서 특정 조건을 만족하는 요소를 제거하는 데 사용된다. 위 예제에서는 'a'가 포함된 단어들을 리스트에서 제거했다.Share article