Archive for March 17, 2014

Java 8 : Double Colon operator

March 17, 2014 2 comments

Double Colon operator introduced in Java 8, We use it as method reference.

Syntax : ClassName::MethodName

for example, if we want to print a list :

List<String> strings = Arrays.asList("one","two");


here forEach is a new method added to the List interface in java 8. System.out is the PrintStream Class and println is method in it.

Complete Example:

import java.util.*;

public class DoubleColon{

public static void display(String name){
System.out.println("Name : "+name);
public static void main(String[] args){
List<String> names = Arrays.asList("one","two","three");

Categories: Java