Skip to content

andrejivanov/javastreams

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

java streams collect method

How to use streams collect method to accumulate periods concatenating if overlapps.

List<Period> periodList = ...
List<Period> concatenatedPeriods = 
      periodList.stream()
        .collect(PeriodList::new, PeriodList::add, PeriodList::combain)
        .get();        

Input:

Period{start=1, end=2}
Period{start=3, end=7}
Period{start=3, end=4}
Period{start=5, end=6}
Period{start=4, end=7}
Period{start=8, end=9}

Output:

Period{start=1, end=2}
Period{start=3, end=7}
Period{start=8, end=9}

About

accumulate overlapping periods with java streams

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages