Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to sort import statements in Eclipse in case insensitive order?

Tags:

java

eclipse

Eclipse sorts import statements within the import groups using lexicographical order, which is case sensitive.

For example :

import com.company.something.DBException;
import com.company.something.DatabaseHandler;

Is it possible to change that automatic sorting to be case insensitive. In the above example, I'd like the order to be :

import com.company.something.DatabaseHandler;
import com.company.something.DBException;
like image 809
Eran Avatar asked Dec 24 '15 10:12

Eran


1 Answers

I found a way to do it: first, there in the Window > Preferences > Java > Code Style > Organize Imports option, delete all the entries that indicate specific packages order:

Delete custom package entries

And then enter one single entry with only a * character.

Add * single entry

Apparently, this indicates you don't want to specify any custom order and then Eclipse decides the order method, which by default seems to be lexicographical.

That's it. Next time you execute the Source > Organize Imports command or the CTRL + SIFT + O shortcut, the order will be lexicographical.

🤓🤯😎

like image 153
Francisco Acevedo Avatar answered Nov 03 '22 05:11

Francisco Acevedo