0

I have an ArrayList that is populated with strings from a text file, and now I want to sort it alphabetically (I can't use collections.sort or anything like that, it has to be manual).

What is the correct way to compare two elements of an ArrayList (if there is one at all)?

8
  • Do you know how to compare two strings? Do you know how to retrieve two items from an array list? If you know both of those, put them together. Commented Feb 13, 2015 at 17:29
  • Care to mention why you can't use Collections.sort for your needs? And FWIW, Strings are Comparable, so compareTo should do for basic lexicographic comparison. Commented Feb 13, 2015 at 17:30
  • stackoverflow.com/questions/6607888/…. Commented Feb 13, 2015 at 17:32
  • It's for an assignment and we're not allowed to use Java Collections for it. And to answer the previous question, yes I do know how to do both of those things, but it's not accepting compareTo. Commented Feb 13, 2015 at 17:33
  • What do you mean by "not accepting" compareTo? Have you read the javadoc of the compareTo to understand how it works? Commented Feb 13, 2015 at 17:36

0

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.