What is Java 8 equivalent method for where
extension method in C#?
How can I filter element of a Hashtable
in Java 8 using lambda expression
What is Java 8 equivalent method for where
extension method in C#?
How can I filter element of a Hashtable
in Java 8 using lambda expression
You need to use the stream filter() function, which takes a Predicate object defining your filtering criteria.
Here's a useful tutorial. Note the usage:
List<User> olderUsers = users.
stream().
filter(u -> u.age > 30).
collect(Collectors.toList());
and the subsequent collection into a collection type of your choice.
Note that I'd likely avoid Hashtable
in preference to HashMap
. See this useful SO entry.
Actually he's asking about hashtable, but there is not much a difference there.
Hashtable<String, Integer> someHashTable;
someHashTable.entrySet().stream().filter((entry)-> entry.getValue()>3).forEach(System.out::println);
Here's the tutorial I've used to understand java8 new features including streams http://winterbe.com/posts/2014/03/16/java-8-tutorial/ best one I've found so far. Enjoy :)