Avatar ·

What does the "::" (double colon) operator mean in Java 8?

Hi everyone! I'm learning Java 8 and came across a strange syntax with double colons "::". I've seen it in examples with lambda expressions, but I don't understand what it specifically does and when to use it. For example, I know how to write a lambda for filtering a list of strings by length:
List<String> list = Arrays.asList("a", "bb", "ccc");
list.stream().filter(s -> s.length() > 1).forEach(s -> System.out.println(s));
But then I saw this code:
list.stream().filter(s -> s.length() > 1).forEach(System.out::println);
Here, instead of `s -> System.out.println(s)`, it says `System.out::println`. What is this magic? Is it the same thing? Why can't I just use a lambda? And how do I know when I can write `::` and when I can't? Can you