Question: the "String::contains" is wrong. but how to express the lambda?

In addition , when I write this in IntelliJ IDEA :

> 
> obj.testPredicate(list, String::contains);
> 
> 
> 

I get the error in "String::contains" : Non-static method cannot be referenced from a static context. but the contains is not static method. I am confused by the tips.

my code as follows:

```
public <T> List<T> testPredicate(List<T> list , Predicate<T> predicate){
    List<T> result = new ArrayList<>();
    for(T t: list){
        if(predicate.test(t)){
            result.add(t);
        }
    }
    return result;
}

```

and this is the caller:

```
@Test
public void testPredicate() throws Exception {
    List<String> listTemp = lambda.testPredicate(list, s -> s.contains("o"));
    System.out.println(listTemp);
}

```

**why the simplest lambda cannot be replace by method reference?** 

and I see the [Using method reference instead of multi argument lambda](https://stackoverflow.com/questions/23139725/using-method-reference-instead-of-multi-argument-lambda).

it says 

> 
> (2) If func is an instance method, then SomeClass::func is a lambda that uses the first argument as the instance, as you thought:
>  (a, b, c) -> a.func(b, c);
> 
> 
> 

there is no defference with my (String a, String b)-> a.contains(b); why method reference did not work?

Answer: 
You can create your own predicates:

```
public class StringPredicates {
  public static Predicate<String> contains(String contained) {
    return s -> s.contains(contained);
  }
}

```

Then you can use them similarly to this:

```
obj.testPredicate(list, StringPredicates.contains("o"));

```

Note, that you don't need method references to use such a construct. As I always say: use the right tool when needed! In this case you have a variable, so it's not advisable to use a method reference.

If you really must use a method reference, you can always write this:

```
public static boolean containsO(String s) {
  return s.contains("o");
}

```

And then use it:

```
obj.testPredicate(list, StringPredicates::containsO);

```
String `contains` method requires one parameter that is "o" in this case.

While filtering on list of string's when we are specifying predicate usual
sytax is a -> a.contains("o").

IntelliJ gives suggestion only when method don't have parameter to method.

e.g. when you are specifying predicate like this:

```
a -> a.isEmpty()

```

Then alternative syntax is `String::isEmpty` which is more readable than the previous one.

But in case of predicate where you need to call method with one or more parameter you don't have alternative way to specify other than this: 
`a -> a.contains`