Here you can find the source of numberOfLines(String text)
public static int numberOfLines(String text)
//package com.java2s; //License from project: Open Source License import java.util.Scanner; public class Main { public static int numberOfLines(String text) { Scanner scanner = new Scanner(text); int i = 0; while (scanner.hasNextLine()) { scanner.nextLine();// ww w.ja v a 2 s . c om i++; } scanner.close(); return i; } }