Little problem.. i want to add some arrays to my arraylist and later get acces to print them out.
Her is my code..
import java.util.*;
class List
{
private ArrayList<int[]> X;
private int[] list;
public X()
{
X = new ArrayList<int[]>();
}
public void addList(int[] list)
{
this.X.add(list);
}
public void showList(int listNumber)
{
System.out.println(X.get(listNumber));
}
Problem is im not getting my list out, but the int code something … dunno what it really is..
This is because arrays
toString()which is called here prints out array reference, not it’s contents.Use instead custom output:
Or, as AlexR proposed, better use provided JDK method
Arrays.toString();By the way, you don’t need to prefix
this.everywhere in your class’ code.