dcsimg
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Java
Expertise: Intermediate
Jul 31, 2018

WEBINAR:

On-Demand

Building the Right Environment to Support AI, Machine Learning and Deep Learning


Understanding the Double Colon in Java

Iterating a list and printing the values is very simple, as illustrated by the code snippet below.

import java.util.*;

public class DoubleColon
{
   public static void main(String args[])
   {
      DoubleColon doubleColon = new DoubleColon();
      doubleColon.proceed();
   }
   
   private void proceed()
   {
      List oddNumbers = new ArrayList();
      //List oddNumbers is created and populated with some odd numbers
      oddNumbers.add(1);
      oddNumbers.add(3);
      oddNumbers.add(5);
      oddNumbers.add(7);
      oddNumbers.add(9);

      System.out.println("Contents of the oddNumbers list");
      //Using the :: here. This explicitly understands and prints the items in the list
      oddNumbers.forEach(System.out::println);   
   }
}

/*

Expected output:

[root@mypc]# java DoubleColon
Contents of the oddNumbers list
1
3
5
7
9

*/
M S Sridhar
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date