Here you can find the source of countLines(String str)
static int countLines(String str)
//package com.java2s; //License from project: Apache License public class Main { static int countLines(String str) { if (str == null || str.isEmpty()) return 0; int lines = 1; int pos = 0; while ((pos = str.indexOf("\n", pos) + 1) != 0) lines++;/*from ww w . j av a 2s . c o m*/ return lines; } }