Tech Master Tutorials
Email Facebook Google LinkedIn Pinterest Twitter
Home Java Java 8 Java Interview Questions Java8 Interview Questions Object Oriented Programming in Java JVM Java Programming

for-each Method in Collection Utility Classes

Using the Lambda Expression for the forEach() method provided in the Java8 version to provide the capability to iterate without any external iterator.

package LambdaExpression;

import java.util.HashSet;

public class LambdaTestInterator {

	public static void main(String[] args) {
		HashSet intSet=new HashSet<>();

		intSet.forEach(intVal -> System.out.println(intVal));