I want to use an Array variable, which is defined in one method, in another method of the same class.
I tried to directly use it but there is an error saying "cannot find variable". I tried to define the Array variable as static in the front but there is an error saying "Array constant can only be used in initializers".
Here is an example:
import java.io.*;
import java.util.*;
public class test{
public static void name(){
String[] list={"a","b"};
}
public static void main(String args[]){
name();
System.out.println(Arrays.toString(list));
}
}
And what I want is just the array named list.
