Here you can find the source of chomp(StringBuilder sb)
public static void chomp(StringBuilder sb)
//package com.java2s; /*/*from ww w.j a va2s .c o m*/ * JBoss, the OpenSource J2EE webOS * * Distributable under LGPL license. * See terms of license at gnu.org. * * Portions of this file Copyright (C) 2013 Jeremy D Monin <jeremy@nand.net> */ public class Main { public static void chomp(StringBuilder sb) { chopIfMatch(sb, '\n'); chopIfMatch(sb, '\r'); } public static String chomp(String input) { StringBuilder sb = new StringBuilder(input); chomp(sb); return sb.toString(); } private static void chopIfMatch(StringBuilder sb, char ch) { if (sb.length() != 0 && sb.charAt(sb.length() - 1) == ch) sb.setLength(sb.length() - 1); } }