Some handy code for JVM8

How to map with casting in Java8

Original code:

 .filter(c -> c instanceof Client)
 .map(c -> (Client) c)

Better one:


How to convert an array to Stream?

Stream<String> str =;
 str.forEach(x -> System.out.println(x));

How to find duplicates in a list?

The following snippet will filter out null values from the given list and then leave only those elements which are duplicated:

List<String> list = 
 Lists.newArrayList("aa", "bb", "cc", null, "aa", "bb", "aa", null, null);
  .filter(tag -> Collections.frequency(list, tag) > 1)

The results of the above code is aa, bb.