0

I've made the array bellow and have no luck sorting it

String[] albums = {"Abbey Road - Beatles","Thriller - Michael Jackson",
    "Queen - News of the World","Gimme Shelter - The Rolling Stones",
    "Pink Floyd - The Dark Side of the Moon"};

Using Collections.sort(albums); gives the error: no suitable method for sort(String[])

I've imported java.util.*; but this error is still persisting

I'm still learning and don't understand how to fix this or what I'm missing

1 Answer 1

2

You have an array (not a Collection). You can use Arrays.sort(T[], Comparator<? super T>) to sort it. Like,

Arrays.sort(albums, Comparator.naturalOrder());
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.