match

Stream API는 최종 처리 단계 에서 요소들이 특정 조건에 만족하는지 조사할 수 있도록 세가지 매칭 메소드를 제공한다. allMatch() 모든 요소들이 매개값으로 주어진 Predicate의 조건을 만족하는지 조사 anyMatch() 최소한 한 개의 요소가 매개값으로 주어진 조건을 만족하는지 조사 noneMatch() 모든 요소들이 매개값으로 주어진 조건을 만족하지 않는지 조사 public static void main(String[] args){ int[] intArr = {2, 4, 6}; boolean result = Arrays.stream(intArr) .allMatch(a -> a%2 == 0); System.out.println("2의 배수? " + result); result = Ar..
Stream을 이용한 2중 for문 우리는 2중 for문을 종종 사용해야할 때가 있다. Stream을 이용하여 2중 for문을 구현해보자. 상황 public static void main(String[] args) { List list1 = Arrays.asList("a", "b", "c", "d", "e"); List list2 = Arrays.asList("a", "b", "d"); // 2중 for문은 stream으로 어떻게 작성할까? // 만약 for문을 돌면서 같은 것만 list에 담고 싶다면? // 8버전 이전 List result1 = new ArrayList(); for(String str1 : list1){ for(String str2 : list2){ if(str1.equals(str2..
깡냉쓰
'match' 태그의 글 목록