Here you can find the source of countLine(String contents, int index)
public static int countLine(String contents, int index)
//package com.java2s; /**/*from w w w. java2s. c om*/ * Copyright (c) 2015 SK holdings Co., Ltd. All rights reserved. * This software is the confidential and proprietary information of SK holdings. * You shall not disclose such confidential information and shall use it only in * accordance with the terms of the license agreement you entered into with SK holdings. * (http://www.eclipse.org/legal/epl-v10.html) */ public class Main { public static int countLine(String contents, int index) { int count = 0; if (index < 0 || index > contents.length()) { return 0; } for (int i = 0; i < index; i++) { if ('\n' == contents.charAt(i)) count++; } return count; } }