List<String> list = stream.collect(Collectors.toList()); list.sort(null); return list.toArray(new String[list.size()]);could be converted to
return stream.sorted().toArray(String[]::new);
Note that sometimes the converted stream chain may replace explicit ArrayList
with Collectors.toList()
or explicit
HashSet
with Collectors.toSet()
. While the current library implementation uses these collections internally,
this is not specified and thus can be changed in future, which may affect the semantics of your code.
If you are concerned about this,
use the checkbox below to suggest Collectors.toCollection()
instead of toList
and toSet
collectors.
This inspection only applies to language level 8 or higher.
New in 2017.3