Here you can find the source of chomp(String str)
public static String chomp(String str)
//package com.java2s; public class Main { public static String chomp(String str) { return chomp(str, "\n"); }/*from w w w .j av a2 s .c om*/ /** * <p> * Remove the last value of a supplied String, and everything after it from * a String. * </p> * * @param str * String to chomp from * @param sep * String to chomp * @return String without chomped ending * @throws NullPointerException * if str or sep is <code>null</code> */ public static String chomp(String str, String sep) { int idx = str.lastIndexOf(sep); if (idx != -1) { return str.substring(0, idx); } else { return str; } } }