Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (7k points)

I want to list an array of strings in alphabetical order. I have tried both

Arrays.sort(hotel);

System.out.println(Arrays.toString(hotel));

 And 

java.util.Collections.sort(hotel);

How can I do it?

1 Answer

0 votes
by (13.1k points)

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]);

    }

}

Want to learn Java? Check out the core Java certification from Intellipaat. 

Related questions

0 votes
1 answer
asked May 9, 2021 in Java by sheela_singh (9.5k points)
0 votes
1 answer
0 votes
1 answer
asked Oct 23, 2019 in Java by Anvi (10.2k points)

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...