I know Each recursive call has its own copy of data stored in its reserved area in the stack.
However how can a recursive call access shared public static data declared in the main for example ?
Is this data in the stack or heap ?
I know Each recursive call has its own copy of data stored in its reserved area in the stack.
However how can a recursive call access shared public static data declared in the main for example ?
Is this data in the stack or heap ?
A recursive method (it doesn't really matter if it's recursive or not) can access static members of the class to which it belongs, as well as non static members (assuming the recursive method is not static). This data is in the heap.
However, if you wish to mutate the array mentioned in your title inside the recursive method, I suggest you pass the array as an argument to each recursive call.
In short: static fields and even methods are stored on the heap. See this question for more in-depth information.
You can access the static field directly from your recursive method as you'd do with any non-static field or local variable. As there is only on accessor (in the sense of read/write access and compared to multi-threading) at a time, it is safe.
In case you want your recursive method threadsafe you might want to favour passing the field (or a Holder class) as parameter.