arrays (little a) work in java without the import statement (import java.util.Arrays), why is this?

Ratchet :

Edit: Previous question was not clearly worded sorry. I was talking about the general arrays working such as int[], String[], char[], ect.

Psymøn :

No, java.util.Arrays is not imported by default.

class Test {
    public static void main(String[] args) {
        int[] a = {1,2};
        int[] b = {1,3};

        System.out.println(Arrays.equals(a,b));
    }
}

Trying to compile this class will fail, due to Arrays being unknown. You will need to prepend the file with import java.util.Arrays; for it to compile.

If you're talking about arrays generally, as in how int[] is supported by default, that's a different question, and you'll need to clarify and reword what you mean. Simply, arrays are supported in C, the language Java is built upon.

EDIT: Further reading here

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=238127&siteId=1