Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java eclipse formatting (unnecessary white space if condition )

On formatting my code Ctrl + Shift + f This is how my code looks

if (item == null) {}

Is it possible to get it formatted like

if(item == null) {}

Thanks,

like image 996
Krishna Kalyan Avatar asked Feb 03 '26 05:02

Krishna Kalyan


2 Answers

You can go to Window > Preferences > Java > Code Style > formatter > Edit > and uncheck option "before opening parenthesis".

enter image description here

like image 117
Ninad Pingale Avatar answered Feb 04 '26 18:02

Ninad Pingale


You can configure formatting profiles on Eclipse.

Just go to Eclipse preferences > Java > Code Style > Formatter.

As the other answer specifies (damn it, that was fast!) you'll find the particular option you're looking for on the before opening parenthesis checkbox displayed when selecting control statements > 'if else' on the white space tab on the edit profile dialog.

Check out these resources too:

http://www.ralfebert.de/archive/java/source_formatting/

Best Eclipse Code Formatters?

like image 37
NotGaeL Avatar answered Feb 04 '26 17:02

NotGaeL



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!