dj5 dj5 - 3 months ago 33
Java Question

The import (java.util.Arrays.sort) cannot be resolved

My professor gave me the java.util.Arrays.sort static method and it shows an error that the import cannot be resolved. This does not happen to any of my other methods. Is this written right?

import java.util.Arrays.sort;

Edit: Does the .sort need to do something? I changed it to

import java.util.Arrays;

and there were no errors.


Importing in Java involves either importing a member class of a package, in this case (java.util is the package, Arrays is the class)

import java.util.Arrays;

or importing the entire package, which would be

import java.util.*; 

There is no concept of importing an individual class method, which is what

import java.util.Arrays.sort;

was attempting to do , because sort is just one method of the java.util.Arrays class (there are many other methods of that class).

So if you attempt to do that, you will get the error message you did.