Perhaps he referred to the XML serialization used by Webservices? Taking advantage of this a few years ago, I remember that the web service returning the List object was hard to connect to (at least I couldn't figure it out, perhaps due to the internal structure of ArrayList and LinkedList s), although it was trivially done when the array was returned.
To send a comment to Reddy,
But in any case (array or ArrayList) is converted to XML, right?
Yes, they will, but XML serialization basically translates into XML all the data contained in the serialized object.
For an array that is a series of values. For example, if you declare and serialize
int[] array = {42, 83};
You will probably get the XML result:
<array>42</array> <array>83</array
For ArrayList , i.e .:
- an array (obviously) that may be larger than the actual number of elements
- several other members, such as integer indices (
firstIndex and lastIndex ), counts, etc.
(you can find it all in source for ArrayList.java )
Thus, all of them will be converted to XML, which makes it difficult for the Webservice client to read the actual values: it must read the index values, find the actual array and read the values ββcontained between the two indexes.
Serialization:
ArrayList<Integer> list = new ArrayList<Integer>(); list.add(42); list.add(83);
might look like this:
<firstIndex>0</firstIndex> <lastIndex>2</lastIndex> <E>42</E> <E>83</E> <E>0</E> <E>0</E> <E>0</E> <E>0</E> <E>0</E> <E>0</E> <E>0</E> <E>0</E>
Thus, when using XML serialization in Webservices, it is better to use arrays (for example, int[] ) than collections (for example, ArrayList<Integer> ). To do this, it may be useful to convert collections to arrays using Collection#toArray() .