Here you can find the source of chop(String str)
Parameter | Description |
---|---|
str | the string we are removing the last char from |
str
with the last char removed. if str
is null
or empty, chop(String) has no effect.
public static String chop(String str)
//package com.java2s; //License from project: Apache License public class Main { /**/*from w w w .j av a 2s. c o m*/ * @param str the string we are removing the last char from * @return <code>str</code> with the last char removed. if <code>str</code> is <code>null</code> or empty, chop(String) has no effect. */ public static String chop(String str) { return (str != null && str.length() > 0) ? str.substring(0, str.length() - 1) : str; } /** * @param str the string to shorten by one char * @param expectedEnd the expected end of <code>str</code> * @return str with the last char chopped off if <code>str</code> ends with <code>expectedEnd</code>, <code>str</code> itself otherwise */ public static String chop(String str, char expectedEnd) { return (str != null && str.length() > 0 && str.endsWith(String.valueOf(expectedEnd))) ? str.substring(0, str.length() - 1) : str; } }