Java program that trims starts and ends public class Program { public static String trimEnd(String value) { // Use replaceFirst to remove trailing spaces. return value.replaceFirst("\\s+$", ""); } public static String trimStart(String value) { // Remove leading spaces. return value.replaceFirst("^\\s+", ""); } public static void main(String[] args) { String value = " /Test? "; // Use custom trimEnd and trimStart methods. System.out.println("[" + trimEnd(value) + "]"); System.out.println("[" + trimStart(value) + "]"); } }
java trim start end space
Guess you like
Origin http://43.154.161.224:23101/article/api/json?id=324932174&siteId=291194637
Recommended
Ranking