String.split() 方法在 eclipse oxygen 版本 4.7.0M2 中不起作用

String.split() method doesn't work in eclipse oxygen version 4.7.0M2

String.split() 方法在 Eclipse Oxygen 版本 4.7.0M2 中不起作用 我准备了一个简单的代码片段

public static void main(String[] args) {
    // TODO Auto-generated method stub
    int T = Integer.parseInt(System.console().readLine());
    while(T > 0)
    {
        int N = Integer.parseInt(System.console().readLine());
        String inp = System.console().readLine();
        String[] inp =   inp.split("\s+");
        T--;
    }
}

split() 在 IDE 中显示错误。我正在使用 JRE 1.8。相同的功能在 Eclipse Luna 中使用相同的 JRE 可以正常工作。 请任何人帮助我了解确切的问题。

您定义了两个同名变量:String inp 和 String[] inp。 为字符串数组指定一个不同的名称。

您收到该错误是因为您尝试对字符串数组调用 split 方法。尝试重命名字符串数组,它将起作用!

    public static void main(String[] args) {
    // TODO Auto-generated method stub
    int T = Integer.parseInt(System.console().readLine());
    while(T > 0)
    {
        int N = Integer.parseInt(System.console().readLine());
        String inp = System.console().readLine();
        String[] inp2 =   inp.split("\s+");
        T--;
    }
}