List an Array of Strings in alphabetical order

前端 未结 11 1449
独厮守ぢ
独厮守ぢ 2020-12-28 14:49

I have a program which has the user inputs a list of names. I have a switch case going to a function which I would like to have the names print off in alphabetical order.

11条回答
  •  不思量自难忘°
    2020-12-28 15:03

    The first thing you tried seems to work fine. Here is an example program.
    Press the "Start" button at the top of this page to run it to see the output yourself.

    import java.util.Arrays;
    
    public class Foo{
        public static void main(String[] args) {
            String [] stringArray = {"ab", "aB", "c", "0", "2", "1Ad", "a10"};
            orderedGuests(stringArray);
        }
    
        public static void orderedGuests(String[] hotel)
        {
            Arrays.sort(hotel);
            System.out.println(Arrays.toString(hotel));
        }
    }
    

提交回复
热议问题