Hello everyone I am in desperate need of help right now. I need to find a way to sort a list of strings alphabetically. I should be able to create a method that will recognise the alphabet but I will take me forever! And I don't have much time! Does anyone know a built-in method or a package that will help me? I've looked through the java.lang.String package but there doesn't seem to be anything helpful in there
I'm not asking anyone to make a code for me, just a package name, web link or something to help me make this method will do fine.
Class Collections is in the package java.util, so yes, you need to import it. Note that you can find all classes, interfaces etc. of the standard Java API in the API documentation. You can download the documentation from the Java SE download page for offline viewing.
Originally posted by Olivier Legat: ...I've looked through the java.lang.String package but there doesn't seem to be anything helpful in there ...
It's the compareTo method. This is what's used behind the scenes when calling Collections.sort on a List of Strings.
In the suggestion to use Collections.sort, I think it was assumed that when you said a "list" of Strings, you meant a collection that implements java.util.List (like an ArrayList, for example). But maybe you meant "list" less formally -- as a way of saying a "bunch" of Strings. In that case, you would need to put the Strings into a real List before using Collections.sort. On the other hand, maybe that's not really what you want. Let us know if this doesn't make sense.