I am trying to learn java - stream. I am able to do simple iteration / filter / map / collection etc.
When I was kind of trying to collect every 3 elements and print as shown here in this example, [collect every 3 elements and print and so on...]
List<String> list = Arrays.asList("a","b","c","d","e","f","g","h","i","j");
int count=0;
String append="";
for(String l: list){
if(count>2){
System.out.println(append);
System.out.println("-------------------");
append="";
count=0;
}
append = append + l;
count++;
}
System.out.println(append);
output:
abc
-------------------
def
-------------------
ghi
-------------------
j
I am not getting any clue how to do this using stream. Should i implement my own collector to achieve this?