Q:

Can returned iterators access private arrays in Java?

I am trying to reduce the amount of memory being used in a Java project I'm working on, and one of the thing I'm looking into is using iterators of arrays, rather that copies of arrays. However, I'm not sure if this will work or not with private data inside of an object. For instance:
public class MyClass {
    private ArrayList<String> data;

    public ArrayList<String> getData(){ return this.data; }
    public Iterator getDataIter(){ return this.data.iterator(); }
}

public static void main(String[] args) {
    MyClass c = MyClass();
    ArrayList<String> copyOfData = c.getData();

    Iterator dataIter = c.getDataIter();
}

As you can see, in main() I couldn't just go c.data because it is private. However, c.getData() will copy the whole array. So here are my questions:

Will dataIter be able to iterate over the values in data, even though it is a private variable?
Will doing this save me any memory because I'm not passing large arrays around anymore?

A:

c.getData() will not copy the whole array, at least, not in the code you pasted.
That makes the rest of the questions moot, but, sure, dataIter works fine here.
I suggest you review how java's memory model works. All non-primitive values (all objects) are passed around in reference form. this.data is a pointer to the array. If you return it, you return a copy of the pointer, which is a small number (64-bit usually), which refers to the array.
You can trivially test this: call .getData(), and modify something in the array. That modification will also occur in the MyClass, because there's just one array, with both the data field as well as the result of calling getData() referencing this one array.

