I'm learning how Streams work in java and I found some examples, but when I am trying to run this, this throws some exceptions because the lambda expressions. I would like to understand why.
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
public class StreamExample {
public static void main (String[] args) {
List number = Arrays.asList(2, 3, 4, 5);
List square = number.stream().map(x-> x*x).collect(Collectors.toList());
List names = Arrays.asList("Reflection","Collection","Stream");
List result = names.stream().filter(s->s.startsWith("S")).collect(Collectors.toList());
}
}
I get these two errors.
Operator '*' cannot be applied to 'java.lang.Object', 'java.lang.Object'
Cannot resolve method 'startsWith' in 'Object'
Thanks for the help