我使用Arrays.toString()方法时一直出现错误。

huangapple go评论79阅读模式
英文:

I keep getting an error when i use Arrays.toString() method

问题

public class GFG {

    public static void main(String[] args) {
        int[] intArr = new int[] { 1, 2, 3, 4 };

        System.out.println(Arrays.toString(intArr));
    }

}

结果:

/GFG.java:16: 错误: 找不到符号
System.out.println(Arrays.toString(boolArr)); 
                   ^
  符号:   变量 Arrays
  位置: 类 GFG
1 错误

我尝试了多次,但一直得到这个错误。问题出在哪里?

英文:
public class GFG { 

    public static void main(String[] args) 
    { 
        int[] intArr = new int[] { 1, 2, 3, 4 }; 
        
        System.out.println(Arrays.toString(intArr)); 
    }
    
} 

Result:

/GFG.java:16: error: cannot find symbol
System.out.println(Arrays.toString(boolArr)); 
                   ^
  symbol:   variable Arrays
  location: class GFG
1 error

I tried a number of times and keep getting this error.
What's the issue here?

答案1

得分: 3

import java.util.*;
public class GFG {
   public static void main(String[] args)
      {
         int[] intArr = new int[] { 1, 2, 3, 4 };

         System.out.println(Arrays.toString(intArr));
        }
    }
英文:

import java.util.* in your code.

Like this

import java.util.*; 
public class GFG { 
   public static void main(String[] args) 
      { 
         int[] intArr = new int[] { 1, 2, 3, 4 };            
      
         System.out.println(Arrays.toString(intArr));             
        }        
    } 

答案2

得分: 2

请注意,这不是一个专业的解释,但这将帮助您理解发生了什么。

您会收到此错误,是因为您没有在您的代码中导入Arrays类。Arrays不是一个关键字,而是一个类。由于它不是一个关键字,编译器不知道它的实现方式。因此,您必须导入该代码的实现。这意味着您必须告诉编译器,“嘿,这是Arrays的意思。”然后编译器知道如何处理Arrays

在您的代码顶部添加以下行。

import java.util.Arrays;

现在编译器知道Arrays的含义。

英文:

Please consider that, this is not a professional explanation. But this will help you to understand what is going on.

You get this error because you have no import the Arrays class into your code. The Arrays is not a keyword. It's a Class. Since it is not a keyword, the compiler doesn't know the implementation of that. So you have to import the implementation of that code. That means you have to tell the compiler, hey this is the meaning of Arrays. Then the compiler knows what to do with Arrays.

Add the following line to the top of your code.

import java.util.Arrays;

Now the compiler knows the meaning of the Arrays.

答案3

得分: 1

你需要导入 import java.util.Arrays

import java.util.Arrays
public class GFG {

    public static void main(String[] args)
    {
        int[] intArr = new int[] { 1, 2, 3, 4 };

        System.out.println(Arrays.toString(intArr));
    }

}
英文:

You need to import import java.util.Arrays

import java.util.Arrays
public class GFG { 

    public static void main(String[] args) 
    { 
        int[] intArr = new int[] { 1, 2, 3, 4 }; 
        
        System.out.println(Arrays.toString(intArr)); 
    }
    
} 

答案4

得分: 0

在你的代码的第一行在类之前导入这个包和类 **Arrays**

**import java.util.Arrays;**
英文:

import this package with class Arrays as the first line of your code before class

import java.util.Arrays;

huangapple
  • 本文由 发表于 2020年8月26日 21:35:06
  • 转载请务必保留本文链接:https://go.coder-hub.com/63598869.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定