LuminousNutria
LuminousNutria

Reputation: 2001

How to order pre-written String[] array elements alphabetically pre-run-time in IntelliJ-IDEA?

I've typed up a bunch of String[] arrays in an interface. I want IntelliJ-IDEA to order the elements alphabetically.

I'm not talking about ordering during run-time or compile-time. I want the actual java/text-file to be modified.

How can I get IntelliJ-IDEA to sort String[] array elements alphabetically and in the ".java" files themselves?

Current Status:

String[] RACES = {
  "human", "elf", "small folk", "orc", "goblin", "aasimar", "tiefling"};

Desired Status:

String[] RACES = {
  "aasimar", "elf",  "goblin", "human", "orc", "small folk", "tiefling"};

Upvotes: 5

Views: 398

Answers (1)

Bas Leijdekkers
Bas Leijdekkers

Reputation: 26482

Position the text cursor inside the array. Type Alt+Enter and choose Sort content. This functionality is available to IntelliJ IDEA 2018.1, and later versions.

Upvotes: 4

Related Questions