I'm attempting a block of code that I can't get quite right. I have a list with say, 1000 string entries (of 3 - 10 characters each) that I collect into a single comma-delimited string. If the total size of the characters in the resulting string is more than 8100, I need to split the list and create TWO comma-delimited strings (or 3, or whatever factor of 8100). I know this needs a groupingBy
, but my syntax isn't working.
So my first question is, how can I determine the sum of the characters in my list, and how can I group the list such that there are no more than 8100 characters in each group of lists? This is what I have so far:
AtomicInteger counter = new AtomicInteger();
String codes = configInfos.stream()
.map(ConfigInfo::getCode)
.collect(Collectors.groupingBy(it -> counter.getAndIncrement() / 8100))