-3
    public class Demo {
  public static void main(String[] args) {
    new Demo().pqr();
  }
   void pqr() {
    List<String> l = new ArrayList<String>();
    l.add("abc");
    l.add("jkl");
    l.forEach(p -> print(p));
  }
  private void print(String l) {
    System.out.println(l);
  }
}

In above code how to replace lambda expression with method referencing

Giriraj
  • 1,251
  • 1
  • 7
  • 10
  • Does this answer your question? [Please Explain Java 8 Method Reference to instance Method using class name](https://stackoverflow.com/questions/32283833/please-explain-java-8-method-reference-to-instance-method-using-class-name) – Joe Feb 25 '22 at 11:29

2 Answers2

1

You can call by

 l.forEach(this::print);

Furthermore, explicit type argument String can be replaced with <>.


List<String> l = new ArrayList<String>();

by

List<String> l = new ArrayList<>();
Zahid Khan
  • 2,130
  • 2
  • 18
  • 31
0

Solution would be

l.forEach(this::print);
Giriraj
  • 1,251
  • 1
  • 7
  • 10