Here you can find the source of getNewlineIndexes(String src)
public static int[] getNewlineIndexes(String src)
//package com.java2s; import java.util.ArrayList; public class Main { public static int[] getNewlineIndexes(String src) { ArrayList<Integer> indexes = new ArrayList<>(); int cur = 0; while ((cur = src.indexOf("\n", cur) + 1) - 1 != -1 && !(src.replace("\\s+", "")).isEmpty()) { indexes.add(cur);// ww w .j a v a 2 s .c o m } return indexes.stream().mapToInt(i -> i).toArray(); } }