/** * @author lautturi.com * Java example: removing white space at the end of string in java */ import java.util.*; public class Lautturi { public static void main(String[] args) { String str = " hello lau java \n "; String newString = str.replaceAll("\\s+$",""); System.out.println(newString); } }
output:
, hello lau java