Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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"};
like image 655
LuminousNutria Avatar asked Jan 04 '19 03:01

LuminousNutria


People also ask

How do you arrange an array of strings in alphabetical order?

JavaScript Array sort() The sort() sorts the elements of an array. The sort() overwrites the original array. The sort() sorts the elements as strings in alphabetical and ascending order.

How do you arrange an array of strings in alphabetical order in Java?

Using the toCharArray() method Get the required string. Convert the given string to a character array using the toCharArray() method. Sort the obtained array using the sort() method of the Arrays class. Convert the sorted array to String by passing it to the constructor of the String array.

What is the code to sort an array of strings in Java?

To sort an array of strings in Java, we can use Arrays. sort() function.


1 Answers

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.

like image 193
Bas Leijdekkers Avatar answered Oct 23 '22 11:10

Bas Leijdekkers