Similar to the question for eclipse,
Type M-x delete-trailing-whitespace to delete all trailing whitespace. This command deletes all extra spaces at the end of each line in the buffer, and all empty lines at the end of the buffer; to ignore the latter, change the variable delete-trailing-lines to nil .
To remove leading and trailing spaces in Java, use the trim() method. This method returns a copy of this string with leading and trailing white space removed, or this string if it has no leading or trailing white space.
The Trim function The most obvious (and generally efficient) method for removing both leading and trailing space is to use the TRIM() function.
You can also enable it on save via the following preference (Editor -> General -> Other):
And for those wondering,
"Always keep trailing spaces on caret line"
If this option is selected, trailing spaces will not be stripped on the line where the caret is placed on save operation (for example, when you switch to another window).
(bigger image)
Ha, it's as simple as Code->Reformat code...
(option-cmd-L)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With