Hey I'm trying to add pairs of numbers into an array by placing them into objects then putting the objects into the arrays but I seem to be having a problem with some part of my code. When I run the following example I just get the following back : [Example$Pair@1fc4bec, Example$Pair@dc8569, Example$Pair@1bab50a and so on...] can someone tell me why this is happening and how do I go about just printing the contents of the arraylist out correctly?
import java.util.*;
public class Example{
ArrayList<Pair> ar1 = new ArrayList<Pair>();
public static void main(String args[]){
Example example = new Example();
example.createArray();
}
public void createArray(){
for(int i = 0; i < 5; i ++){
ar1.add(new Pair(i, i+1));
}
System.out.println(ar1);
}
class Pair{
int x = 0;
int y = 0;
public Pair(int a, int b){
x = a;
y = b;
}
}
}