I already asked this question and I got additional question about using class I made myself. see code below.
import java.util.*;
class Pair{
int toWhere;
int weight;
}
public class Test{
public static void main(String[] args){
ArrayList[] arr = new ArrayList[2];
Pair p = new Pair();
for(int i=0; i<arr.length; i++)
arr[i] = new ArrayList<Pair>();
p.toWhere = 1;
p.weight = 2;
arr[0].add(p);
System.out.println(p); // gives me Pair@525483cd
System.out.println(arr[0].get(0)); // gives me exactly the same, Pair@525483cd
System.out.println(p.toWhere); // gives me no error, and is 1
System.out.println(arr[0].get(0).toWhere); // gives me an error
}
}
my question is this.
values of p and arr[0].get(0) (which is address? I guess) is the same.
but why does p.toWhere give me the accurate value and
arr[0].get(0).toWhere does not?
ArrayList<Pair>[]