Question

I'm running javac v1.6.0-65 in a Dr. Java studio on a Mac with OSX 10.9.1

I get the following warning:

Quick.java:53: warning: [deprecation] readStrings() in In has been deprecated

which isn't so bad, I guess, except I also get the following error:

Quick.java:54: sort(java.lang.Comparable[],int,int) in Quick cannot be applied to (java.lang.String[])

The code lines are:

public static void main(String[] args) 
{ // Read strings from standard input, sort them, and print. 
   String[] a = In.readStrings(); 
   sort(a); 

and

private static void sort(Comparable[] a, int lo, int hi)
{

There seems to be some mismatch in defining the array a of input, String[] a, as something that can be compared in the private sort(). I thought strings could be compared.

My question is, how do I get rid of the error? And, incidentally, does the warning relate to the error?

Was it helpful?

Solution

To get rid of the deprecated warning, don't use a deprecated function. Deprecated functions may not meet current standards. They exist only to provide backwards compatibility while the rest of the world catches up. In your case, use another Stream reader instead. I prefer Scanner, but there are plenty more.

Scanner in = new Scanner(System.In);
String[] strings = in.readLine().split(" ");

Java has a built in Arrays.Sort() method that you can use instead of implementing your own, unless you have some special requirements.

Arrays.sort(strings);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top