Conversion of Set To Stream in Java\\n



Being a type of Collection, we can convert a set to Stream using its stream() method.

Example

Live Demo

import java.util.HashSet; import java.util.Set; import java.util.stream.Stream; public class Tester {    public static void main(String args[]) {       Set<String> set = new HashSet<String>();       set.add("a");       set.add("b");       set.add("c");       set.add("d");       set.add("e");       set.add("f");       Stream<String> stream = set.stream();       stream.forEach(data->System.out.print(data+" "));    }   }

Output

a b c d e f
Updated on: 2020-06-18T15:31:03+05:30

922 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements