Back
I want to list an array of strings in alphabetical order. I have tried both
Arrays.sort(hotel);System.out.println(Arrays.toString(hotel));
Arrays.sort(hotel);
System.out.println(Arrays.toString(hotel));
And
java.util.Collections.sort(hotel);
How can I do it?
You can try like this:
import java.util.Arrays;public class Test{ public static void main(String[] args) { // args is the list of guests Arrays.sort(args); for(int i = 0; i < args.length; i++) System.out.println(args[i]); }}
import java.util.Arrays;
public class Test
{
public static void main(String[] args)
// args is the list of guests
Arrays.sort(args);
for(int i = 0; i < args.length; i++)
System.out.println(args[i]);
}
Want to learn Java? Check out the core Java certification from Intellipaat.
31k questions
32.8k answers
501 comments
693 users