# Organize Imports

# Properties

Property Value
Rule ID OrganizeImports
First seen in jSparrow version 1.0.0
Minimum Java version 1.1
Remediation cost 1 min
Links S1128

# Description

Organizes the imports of a Java class. Removes unused imports and applies an alphanumeric order.

# Benefits

Imports that are not used are optimized away by the compiler. Regardless, they clutter up the file and might lead to confusion. Removing unused imports and applying alphanumeric order improves readability and maintainability.

# Code Changes

Pre

package at.splendit.simonykees.sample.preRule;
import java.util.ArrayList;
import java.util.Locale;
import java.util.List;
import java.util.stream.*;
import org.apache.commons.lang3.StringUtils;
public class OrganiseImportsRule {
    public String a(String s) {
        return StringUtils.upperCase(s, Locale.CANADA_FRENCH);
    }
    public String b(String s) {
        List<String> list = new ArrayList<>();
        list.add(s);
        return list.get(list.indexOf(s));
    }
}

Post

package at.splendit.simonykees.sample.postRule.allRules;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import org.apache.commons.lang3.StringUtils;
public class OrganiseImportsRule {
    public String a(String s) {
        return StringUtils.upperCase(s, Locale.CANADA_FRENCH);
    }
    public String b(String s) {
        List<String> list = new ArrayList<>();
        list.add(s);
        return list.get(list.indexOf(s));
    }
}

Automatic Application of This Rule

The automatic application of this rule is supported in the following jSparrow versions:

# Tags

1
default
You & jSparrow
default

Hey there! May I help you? 😊