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"};
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.
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.
To sort an array of strings in Java, we can use Arrays. sort() function.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With