Here you can find the source of countLines(String text)
private static int countLines(String text)
//package com.java2s; /******************************************************************************* * Copyright (c) 2004, 2006 IBM Corporation and others. * All rights reserved. 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.eclipse.org/legal/epl-v10.html * * Contributors:/* ww w. j ava 2 s.c o m*/ * IBM Corporation - Initial API and implementation *******************************************************************************/ public class Main { private static int countLines(String text) { int newLines = 1; for (int i = 0; i < text.length(); i++) { if (text.charAt(i) == '\n') { newLines++; } } return newLines; } }