0

I am trying to convert a string array into an arraylist. However, when I use this code to print the list, it returns values like this @3fec1b24. Could anyone help me with this?

ArrayList<String[]> dataList = new ArrayList<>();
dataRow = new String[nc];
dataList.add(dataRow);
  • To print the contents of an *array*, use `Arrays.toString(arr)` instead of relying on the default implementation of the `toString()` method on array instances. – janos Nov 26 '17 at 09:12
  • 1
    BTW: `ArrayList` is a list *of* arrays, so what's that got to do with converting array to list? If you want the strings in the `dataRow` array to be added to a list, declare the list as `ArrayList` then do this: `dataList.addAll(Arrays.asList(dataRow));` – Andreas Nov 26 '17 at 09:12
  • @janos If I use Arrays.toString(dataRow), the add method does not work. It throws the error The method add(String[]) in the type ArrayList is not applicable for the arguments (String) – Keerthi Reddy Nov 26 '17 at 09:14
  • @Andreas I want to convert it into a list of arrays – Keerthi Reddy Nov 26 '17 at 09:16
  • if you have string array like this `String[] strArray = {"AAA"}`, Then use `List strList = new ArrayList<>(Arrays.asList(strArray));` , You can change it as the dimension you want. – Ebraheem Alrabeea Nov 26 '17 at 10:29
  • It's because you add dataRow address as first element to datalist array. – Mehran Zamani Nov 26 '17 at 10:50

0 Answers0