How to auto-format code in Eclipse?
CTRL + SHIFT + F will auto format your code (whether it is highlighted or non highlighted).
Another option is to go to Window->Preferences->Java->Editor->SaveActions and check the Format source code option. Then your source code will be formatted truly automatically each time you save it.
On Windows and Linux : Ctrl + Shift + F
On Mac : ⌘ + ⇧ + F
(Alternatively you can press Format
in Main Menu > Source)