Here you can find the source of countLines(String what)
static public int countLines(String what)
//package com.java2s; /**//from ww w. j a v a 2 s . co m * Copyright (c) 2010 Ben Fry and Casey Reas * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.opensource.org/licenses/eclipse-1.0.php */ public class Main { /** * Get the number of lines in a file by counting the number of newline * characters inside a String (and adding 1). */ static public int countLines(String what) { int count = 1; for (char c : what.toCharArray()) { if (c == '\n') count++; } return count; } }