So my current code is:
int x = 5;
int[] one = new int[1];
one[0] = x;
int[] two = new int[1];
two[0] = x;
x = 10;
System.out.println(one[0]);
System.out.println(two[0]);
The aim here is to get an output of two 10's. Instead what I get is two 5's being printed.
I know that in C++ there is a way of saying &x to refer to a reference type however I don't know of anything similar in Java?
I'd be really grateful if someone could help me out here.
EDIT
Cheers guys. I ended up making my own class and using that instead.
class Ideone {
public static void main (String[] args) throws java.lang.Exception
{
MyTester x = new MyTester();
x.i = 5;
MyTester[] one = new MyTester[1];
one[0] = x;
MyTester[] two = new MyTester[1];
two[0] = x;
x.i = 10;
System.out.println(one[0].i);
System.out.println(two[0].i);
}
}
class MyTester
{
public MyTester() {}
public int i;
}