How to use method referencing for a private method in same class

    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


Solution 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<>();