Here you can find the source of countLine(CharSequence str)
public static int countLine(CharSequence str)
//package com.java2s; /******************************************************************************* * Copyright (c) 2014,2015 Hideki Yatomi * 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 ******************************************************************************/ public class Main { public static int countLine(CharSequence str) { int count = 0; for (int i = 0; i < str.length(); i++) { if (str.charAt(i) == '\n') count++;/*from w ww . j a v a2 s . c o m*/ } if ((str.length() > 0) && (str.charAt(str.length() - 1) != '\n')) count++; return count; } }