Here you can find the source of chop(String str)
public static String chop(String str)
//package com.java2s; //License from project: Open Source License public class Main { public static String chop(String str) { if (str == null) { return null; }//from w w w. j a va 2 s . co m int strLen = str.length(); if (strLen < 2) { return ""; } int lastIdx = strLen - 1; String ret = str.substring(0, lastIdx); char last = str.charAt(lastIdx); if (last == '\n') { if (ret.charAt(lastIdx - 1) == '\r') { return ret.substring(0, lastIdx - 1); } } return ret; } }