// Java code to print the elements of Stream // without using double colon operator import java.util.stream.*; classGFG{ publicstaticvoidmain(String[] args) { // Get the stream Stream<String> stream = Stream.of("Geeks", "For", "Geeks", "A", "Computer", "Portal"); // Print the stream stream.forEach(s -> System.out.println(s)); } }
// Java code to print the elements of Stream // using double colon operator import java.util.stream.*; classGFG{ publicstaticvoidmain(String[] args) { // Get the stream Stream<String> stream = Stream.of("Geeks", "For", "Geeks", "A", "Computer", "Portal"); // Print the stream // using double colon operator stream.forEach(System.out::println); } }
// Java code to show use of double colon operator // for static methods import java.util.*; classGFG{ // static function to be called staticvoidsomeFunction(String s) { System.out.println(s); } publicstaticvoidmain(String[] args) { List<String> list = new ArrayList<String>(); list.add("Geeks"); list.add("For"); list.add("GEEKS"); // call the static method // using double colon operator list.forEach(GFG::someFunction); } }
// Java code to show use of double colon operator // for instance methods import java.util.*; classGFG{ // instance function to be called voidsomeFunction(String s) { System.out.println(s); } publicstaticvoidmain(String[] args) { List<String> list = new ArrayList<String>(); list.add("Geeks"); list.add("For"); list.add("GEEKS"); // call the instance method // using double colon operator list.forEach((new GFG())::someFunction); } }
// Java code to show use of double colon operator // for instance method of arbitrary type import java.util.*; classTest{ String str=null;
Test(String s) { this.str=s; }
// instance function to be called voidsomeFunction() { System.out.println(this.str); } } classGFG{ publicstaticvoidmain(String[] args) { List<Test> list = new ArrayList<Test>(); list.add(new Test("Geeks")); list.add(new Test("For")); list.add(new Test("GEEKS")); // call the instance method // using double colon operator list.forEach(Test::someFunction); } }
// Java code to show use of double colon operator // for class constructor import java.util.*; classGFG{ // Class constructor publicGFG(String s) { System.out.println("Hello " + s); } // Driver code publicstaticvoidmain(String[] args) { List<String> list = new ArrayList<String>(); list.add("Geeks"); list.add("For"); list.add("GEEKS"); // call the class constructor // using double colon operator list.forEach(GFG::new); } }