import java.io.IOException;
import java.util.ArrayList;
public class CheckClass {
static ArrayList<String> curr2=new ArrayList<>();
public static void main(String[] args) throws IOException
{
ArrayList<String> curr=new ArrayList<>();
System.out.println(curr);
CheckArr(curr);
System.out.println(curr);
}
private static void CheckArr(ArrayList<String> curr) {
curr2.add("hi");
curr=curr2;
System.out.println(curr);
}
}
Its output is :
[]
[hi]
[]
Can anyone explain how i can change the reference of curr to curr2. I just switched from C++ to java. I think it has something to do with internal pointer mechanism of java, can you explain this concept.