String str = "apple "; str = StringUtil.trimEnd(str, ' '); System.out.println(str); // Output: "apple"
String str = "donkey\t\n"; str = StringUtil.trimEnd(str, '\t'); System.out.println(str); // Output: "donkey\n"In this example, the method removes the tab character at the end of the String "donkey\t\n" and returns a new String without the trailing tab. Overall, StringUtil.trimEnd is a useful method for removing trailing characters from Strings in Java applications.