This is a follow up question of How to map strings to URIs?
I have a String
of URIs delimited with some white spaces.
http://...[sp]http://...[sp]http://...
I'm trying to split it and, finally, collect them to a List
.
I, so far, wrote following codes.
final List<URI> uris = Stream.of(string.split("\\s"))
.distinct()
.filter(s -> s.isEmpty())
.map(s -> {
try {
return new URI(s);
} catch (final URISyntaxException urise) {
return null;
}
})
.filter(uri -> uri != null)
.collect(Collectors.toList());
My question is,
- Is
null
creation by URI constructor and following filtering is inevitable? - Is there any more effective way to do this?