The code works when I used java.util.Arrays.sort(numbers);
Am I doing something wrong? This seems weird to me.
import java.util.Arrays.*;
class Test {
public static void main(String[] args) {
double[] numbers = {6.0, 4.4, 1.9, 2.9, 3.4, 3.5};
char[] chars = {'a', 'A', '4', 'F', 'D', 'P'};
sort(numbers);
System.out.println(binarySearch(numbers, 3));
}
}
(Error displayed in terminal)
Test.java:8: error: cannot find symbol
sort(numbers);
^
symbol: method sort(double[])
location: class Test
Test.java:10: error: cannot find symbol
System.out.println(binarySearch(numbers, 3));
^
symbol: method binarySearch(double[],int)
location: class Test
2 errors
Misspelled method name Misspelling an existing method, or any valid identifier, causes a cannot find symbol error. Java identifiers are case-sensitive, so any variation of an existing variable, method, class, interface, or package name will result in this error, as demonstrated in Fig.
The “cannot find symbol” error comes up mainly when we try to use a variable that's not defined or declared in our program. When our code compiles, the compiler needs to verify all the identifiers we have. The error “cannot find symbol” means we're referring to something that the compiler doesn't know about.
It means that either there is a problem in your Java source code, or there is a problem in the way that you are compiling it.
Created right after the release of the language, the Java logo depicted a blue coffee cup with red steam above it. The symbol was a tribute to the Java developers, who drank a lot of coffee while working on the language. As it was mostly coffee from Java coffee beans, the name and the symbol were chosen fast enough.
It's a static method of the class Arrays.
You should invoke it like this:
Arrays.sort(someArray);
Note you still have to import the Arrays class like this:
import java.util.Arrays;
Or as others have mentioned, if you do a static import you can omit the class name.
I would argue that Arrays.sort()
is better for readability.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With