I have a task:
A sequence of positive integers numbers and a sequence of strings stringList are given. Get a new sequence of strings according to the following rule: for each value n from sequence numbers, select a string from sequence stringList that starts with a digit and has length n.
If there are several required strings in the stringList sequence, return the first; if there are none,then return the string "Not found"
For example:
input: {1, 3, 4}, {"1aa", "aaa", "1", "a"}
output: {"1", "1aa", "Not Found"}
My output:
[java.util.stream.ReferencePipeline$3@7f690630,
java.util.stream.ReferencePipeline$3@edf4efb,
java.util.stream.ReferencePipeline$3@2f7a2457]
My code:
(List<Integer> numbers, List<String> stringList) {
return numbers.stream()
.map(Object::toString)
.map(value -> (stringList.stream().filter(e -> (Character.isDigit(e.charAt(0)))).map(s -> {
if (((Object) (s.length())).toString().equals(value)) return s;
return "Not Found";
}))).map(Object::toString).collect(Collectors.toList());
help, please.