I am trying to remove all white spaces at the end of string (empty line and tab and everything spaces at the end)
public static void main(String[] args) {
String test = "This is test message.\n"
+ "\n"
+ "\n"
+ "\n"
+ "\n"
+ " \n"
+ "";
System.out.println(test.replaceAll("[\\s\\n]*$", ""));
}
I tried using trip() and stripTrailing() methods but it did not remove empty lines hence trying with regex. But it is not removing. Any idea why it is not working?
