First, configure the formatter
Choose window → preferences from the Eclipse main menu and go to the Code formatter Settings page. As shown in the following:
Confirm that the selected format configuration is eclipse [built-in].
Note: You will need to press CTRL+SHIFT+F to format the code after writing the code. (Eclipse adaptation)
Second, configure save Actions:
After you configure the save actions, Eclipse can automatically do the following after the file is saved:
Automatic format code, remove extraneous comments, spaces, lines, automatically introduce packages, remove unnecessary packages, remove non-referenced variables, automatically add comments (@Override, @Deprecated), etc.
Automatic format source code function, generally we are directly ctrl+shift+f manual format, compared to waste time. The default is not to turn this feature on.
Specific methods:windows–>preferences–>java–> Editor–>save Actions,
Ref: 71523757
Code formatting configuration in Eclipse