最近在Code Wars上注册,我正在做第一个练习,您必须在句子中按数字对单词进行排序。

public class Application {

public static void main(String[] args) {
    String word = "is2 Thi1s T4est 3a";
    System.out.println(order(word));

}

public static String order(String words) {
    String end = "";

    String[] words2 = words.split(" ");

    ArrayList<String> wordss = new ArrayList<String>(Arrays.asList(words2));

    for (int i = 1; i <= wordss.size(); i++) {
        String number = Integer.toString(i);
        for (String words1 : wordss) {
            if (words1.contains(number)) {
                end += words1 + " ";
            }
        }

    }
    return end;
}

}

我在NetBeans上进行了练习,它工作得很好,但是当我将此代码粘贴到CodeWars编译器中时,出现此错误:
./src/main/java/Order.java:10: error: cannot find symbol
   List<String> wordss = new ArrayList<String>(Arrays.asList(words2));
   ^
 symbol:   class List
 location: class Order
./src/main/java/Order.java:10: error: cannot find symbol
   List<String> wordss = new ArrayList<String>(Arrays.asList(words2));
                             ^
 symbol:   class ArrayList
 location: class Order
./src/main/java/Order.java:10: error: cannot find symbol
   List<String> wordss = new ArrayList<String>(Arrays.asList(words2));
                                               ^
 symbol:   variable Arrays
 location: class Order
3 errors

可能是什么原因?

最佳答案

您必须导入arraylist>。<

关于arrays - 找不到arraylist : works in Netbeans but doesnt work in Codewars compiler的符号错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/59321689/

10-09 03:41