java - 如何在 IntelliJ-IDEA 中按字母顺序在运行前按字母顺序排列预写的 String[] 数组元素?

标签 java arrays string sorting intellij-idea

我在界面中键入了一堆 String[] 数组。我希望 IntelliJ-IDEA 按字母顺序排列元素。

我不是在谈论运行时或编译时的排序。我想要修改实际的 java/文本文件。

如何让 IntelliJ-IDEA 按字母顺序和“.java”文件本身对 String[] 数组元素进行排序?

当前状态:

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

期望状态:

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

最佳答案

将文本光标定位在数组内。键入 Alt+Enter 并选择 Sort content。此功能适用于 IntelliJ IDEA 2018.1 及更高版本。

关于java - 如何在 IntelliJ-IDEA 中按字母顺序在运行前按字母顺序排列预写的 String[] 数组元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54032791/

相关文章:

python - 将字符串相乘,使其垂直向下移动一页?

java - 致命异常 : android. app.RemoteServiceException Context.startForegroundService() 然后没有调用 Service.startForeground()

java - 如何根据函数的输出在 @Query 中使用查询字符串

java - Spring Data MongoDB 和批量更新

javascript - Angular 7 - 将数据添加到数组而不是替换它

Android:无法从字符串转换为可编辑

c - 带命令行参数的后缀表达式,段错误? C

java - 为什么这个 if 语句不会短路?

php - 从 PHP 的多维数组中获取数组值的数组

java - 在 java 中,使用 "new"初始化数组有什么好处?