Search code examples
javatoarray

java lang error when using toArray()


Here is my basic setup:

ArrayList<String> myList = new ArrayList<>();
myList.add("test");
String[] arr = myList.toArray(new String[myList.size()]);
System.out.println(arr);

And i get the classic error: [Ljava.lang.String;@1540e19d

Can anyone explain and help me fix it?


Solution

  • Use

    for(String s : arr){
        System.out.println(s);
    }
    

    Instead of System.print.out();