【问题标题】:How do I add a string to an arraylist if the string is two or more words long?如果字符串长度为两个或多个单词,如何将字符串添加到数组列表?
【发布时间】:2014-12-08 17:20:20
【问题描述】:

如果字符串长度为两个或多个单词,如何将字符串添加到数组列表中?

Scanner in = new Scanner(System.in);

System.out.println("Please enter your song name: ");
        Track_name.add(in.next());
        System.out.println("Song name added ✅");

如果我使用它,它会在数组中添加两个字符串。我希望能够将两个单词添加为一个字符串。

【问题讨论】:

  • nextLine() 应该可以吗?

标签: java arrays eclipse string arraylist


【解决方案1】:

nextLine() 取整行输入:

Track_name.add(in.nextLine());

【讨论】:

    猜你喜欢
    • 2021-08-22
    • 2014-05-06
    • 2017-04-19
    • 1970-01-01
    • 2021-02-16
    • 1970-01-01
    • 2017-06-08
    • 1970-01-01
    • 2020-08-14
    相关资源
    最近更新 更多