*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Arrays.sort Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Arrays.sort" Watch "Arrays.sort" New topic
Author

Arrays.sort

susana miranda
Greenhorn

Joined: May 21, 2008
Posts: 9
Hi I have the following code:



and when compiling...

%/SCJP/exercises$ javac TestSortCollections.java
TestSortCollections.java:37: cannot find symbol
symbol : method sort(Dog[])
location: class Arrays
Arrays.sort(myDogs);
^
1 error


I can't understand why, I am implementing Comparable and also compareTo, what is the problem with Arrays.sort ?

Thnaks so much.
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

Make sure you don't have a class called "Arrays" in your classpath.


[My Blog]
All roads lead to JavaRanch
Harpreet Singh janda
Ranch Hand

Joined: Jan 14, 2010
Posts: 317

Your code is fine and below is the output:

Prithvi Sehgal
Ranch Hand

Joined: Oct 13, 2009
Posts: 774
Hi.

The error means that, your compiler is picking a Arrays class which is not having the sort method defined within it.
Please make sure, you don't have any Arrays class on the class-path.

Additionally, for the more meaningful output, i will suggest you over-load the toString() method in Dog class like this,


It will surely produce a more meaningful output for you which you desire.

Hope this helps,


Prithvi,
My Blog, Follow me on Twitter,Scjp Tips, When you score low in mocks, Generics,Scjp Notes, JavaStudyGroup
Harpreet Singh janda
Ranch Hand

Joined: Jan 14, 2010
Posts: 317

"Arrays" is a system class and it must be in placed.
Vlado Zajac
Ranch Hand

Joined: Aug 03, 2004
Posts: 245
Christophe Verré wrote:Make sure you don't have a class called "Arrays" in your classpath.

Or use fully qualified name:
Prithvi Sehgal
Ranch Hand

Joined: Oct 13, 2009
Posts: 774
For sure, the Arrays class he is using is conflicting with the collections Array class. Correctly said above, use the
fully qualified package name.

Hope this helps,
susana miranda
Greenhorn

Joined: May 21, 2008
Posts: 9
Yes!! what the.. , I had a Arrays class in the same directory a was trying to compile.

I used the qualified package name and it compiles!

Ok! Thanks so much to everybody!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Arrays.sort
 
Similar Threads
'void' type not allowed here
Learning about objects
Why cant I do this?
Class dog problems
Where is this line coming from??