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?

Jan Schultke
  • 17,446
  • 6
  • 47
  • 96

4 Answers4

3

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));             
        }        
    } 
SSK
  • 3,444
  • 6
  • 32
  • 59
2

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.

Buddhika Chathuranga
  • 1,334
  • 2
  • 13
  • 22
1

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)); 
    }
    
} 
Javier G.Raya
  • 230
  • 1
  • 3
  • 15
0

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

import java.util.Arrays;

neha
  • 62
  • 5