IntelliJ IDEA中‘Sort array content’功能无法显示,如何启用?
Hey there! Let's break down why you can't find the 'Sort array content' feature and how to resolve this:
1. The Root Cause: Version Compatibility
The 'Sort array content' quick-fix feature was introduced in IntelliJ IDEA 2020.1—your current version (IU-181.4203.550, 2018.1) is way older and doesn't include this functionality at all. No amount of enabling Java inspections or adjusting your array's modifiers will make it appear, since the feature simply doesn't exist in that release.
2. What You Can Do Next
Option 1: Upgrade to a Newer Version
If you want access to this specific feature, upgrading to IntelliJ IDEA 2020.1 or later will make the 'Sort array content' prompt appear when you hover over or place your cursor on an unsorted array like String[] sortMe = { "World", "Hello", "ABC" };.
Option 2: Use a Manual Workaround (For Your Current Version)
If you can't upgrade right now, you can still sort your array easily with these steps:
- Add the
Arrays.sort()call manually:import java.util.Arrays; public class YourClass { private static final String[] sortMe = { "World", "Hello", "ABC" }; public static void main(String[] args) { Arrays.sort(sortMe); // This will sort your array lexicographically } } - Alternatively, select the array variable, press
Alt+Enter(the Show Context Actions shortcut), and check if there are any older refactoring or quick-fix options available (though none will be as direct as the 'Sort array content' feature).
内容的提问来源于stack exchange,提问作者Christian Neverdal

