Drop all while condition not meet dropWhile(),dropWhile(Predicate<T> predicate)
Categories: Java 9 Java 8(JDK1.8) Java Java Examples
package r4r.co.in;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
public class DropWhileExamples {
//Drop all while condition not meet
public static void main(String[] args) {
// Unordered stream- non-deterministic
Set<Long> set=Set.of(1L, 5L, 7L, 10L, 11L, 12L).stream().dropWhile(value -> value % 2 != 0).collect(Collectors.toSet());
System.out.println(set);
// Order stream
List<Long> list=List.of(1L, 5L, 7L, 10L, 11L, 12L).stream().dropWhile(value -> value % 2 != 0).collect(Collectors.toList());
System.out.println(list);
}
}
OutPut:-
[5, 7, 10, 11, 12]
[10, 11, 12]