0

I am trying to turn an ArrayList into a List, but every time I try to run the code, I receive 3 [Ljava.lang.Integer;@10613c5c[I@145eaa88, I know the 3 is int t, but I have no idea what the random String afterward is.

int t=0;
    int test []= {1,2,3,4};
    ArrayList<Integer> x=new ArrayList<Integer>();//Making an ArrayList.
    x.add(10);//Adding to the ArrayList.
    x.add(67);
    x.add(12);
    Integer[] array = new Integer[x.size()];//Code I got from this website from another question.
    array = x.toArray(array);
    for(int i=0;i<x.size();i++)//int t is the size of the ArrayList.
    {
        t++;
    }
    System.out.println(t+" "+array+""+test);//This is the problem.
  • If you want "good" output you should print the `ArrayList`, don't turn it into an array first. `Collection`s have a built-in pretty printer, arrays do not. Use `Arrays.toString()` if you want to pretty print an array. – markspace Aug 02 '20 at 23:58
  • Does this answer your question? [What's the simplest way to print a Java array?](https://stackoverflow.com/questions/409784/whats-the-simplest-way-to-print-a-java-array) – user3341564 Aug 02 '20 at 23:59

0 Answers0