题解 | #字符串排序#

字符串排序

http://www.nowcoder.com/practice/5af18ba2eb45443aa91a11e848aa6723

import java.util.*;

/**
 * 【字符串排序】
 *
 *  描述:给定 n 个字符串,请对 n 个字符串按照字典序排列。
 */
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int nextInt = sc.nextInt();

        ArrayList<String> arrayList = new ArrayList<>();
        for (int i = 0; i < nextInt; i++) {
            String next = sc.next();
            arrayList.add(next);
        }
        Collections.sort(arrayList);
        //arrayList.sort(String::compareTo);

        for (String s : arrayList) {
            System.out.println(s);
        }
    }
}

全部评论

相关推荐

不愿透露姓名的神秘牛友
2025-12-14 11:05
谦虚的小冤种在加班:确实烂白菜,当年本科毕业字节给给开了66*15,哥们都不带看一眼的😋
点赞 评论 收藏
分享
2025-12-26 10:52
河北传媒学院 Java
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务