{"action":"opened","issue":{"url":"https://api.github.com/repos/codenameone/CodenameOne/issues/1715","repository_url":"https://api.github.com/repos/codenameone/CodenameOne","labels_url":"https://api.github.com/repos/codenameone/CodenameOne/issues/1715/labels{/name}","comments_url":"https://api.github.com/repos/codenameone/CodenameOne/issues/1715/comments","events_url":"https://api.github.com/repos/codenameone/CodenameOne/issues/1715/events","html_url":"https://github.com/codenameone/CodenameOne/issues/1715","id":140120878,"number":1715,"title":"ArrayList toArray behaviour different on different platforms","user":{"login":"triplesub","id":9727930,"avatar_url":"https://avatars.githubusercontent.com/u/9727930?v=3","gravatar_id":"","url":"https://api.github.com/users/triplesub","html_url":"https://github.com/triplesub","followers_url":"https://api.github.com/users/triplesub/followers","following_url":"https://api.github.com/users/triplesub/following{/other_user}","gists_url":"https://api.github.com/users/triplesub/gists{/gist_id}","starred_url":"https://api.github.com/users/triplesub/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/triplesub/subscriptions","organizations_url":"https://api.github.com/users/triplesub/orgs","repos_url":"https://api.github.com/users/triplesub/repos","events_url":"https://api.github.com/users/triplesub/events{/privacy}","received_events_url":"https://api.github.com/users/triplesub/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2016-03-11T08:27:57Z","updated_at":"2016-03-11T08:27:57Z","closed_at":null,"body":"This code behaves differently on iOS and the simulator:\r\n```\r\nArrayList<String> parts = new ArrayList<String>();\r\nparts.add(\"One\");\r\nparts.add(\"Two\");\r\n\r\nparts.toArray(new String[]{}); // (1) Works on simulator. Throws exception on iOS saying the array must be big enough.\r\nparts.toArray(new String[parts.size()]); // (2) Works everywhere I have tried.\r\n```\r\n\r\n(2) is more efficient but the Javadoc for ArrayList.toArray states that either should work:\r\n\r\n\"Returns an array containing all elements contained in this ArrayList. If the specified array is large enough to hold the elements, the specified array is used, otherwise an array of the same type is created. If the specified array is used and is larger than this ArrayList, the array element following the collection elements is set to null.\""}}