Java Set foreach Example - Coded Java

Latest

Quality & Simple Java Content

Dec 31, 2017

Java Set foreach Example

Java Set foreach Example

Java Set foreach Example

Set

  Set<String> colourSet = new HashSet<>();
  colourSet.add("RED");
  colourSet.add("GREEN");
  colourSet.add("BLUE");
  colourSet.add("YELLOW");
  colourSet.add("BLACK");
  colourSet.add("WHITE");

  for (String color : colourSet){
System.out.println( color);
  }

Java 8 Lambdas

  colourSet.forEach(color -> System.out.println(color));


Reference


https://docs.oracle.com/javase/1.5.0/docs/guide/language/foreach.html

No comments:

Post a Comment