void (StringBuilder res, String[] srcLines, int from, int to, int requiredLineNumber) { if (to - from > requiredLineNumber) { List<String> strings = compactLines(Arrays.asList(srcLines).subList(from, to) ,requiredLineNumber); int separatorsRequired = requiredLineNumber - 1; for (String s : strings) { res.append(s); if (separatorsRequired-- > 0) { res.append(myLineSeparator); } } res.append(myLineSeparator); } else if (to - from <= requiredLineNumber) { for (int i = from; i < to; i++) { res.append(srcLines[i]).append(myLineSeparator); } for (int i = 0; i < requiredLineNumber - to + from; i++) { res.append(myLineSeparator); } } }