Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Unable to understand toArray()

 
Maitri Solanki
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

The above program works fine and produces the output as mentioned.
The size of array "ia2" is smaller than the size of the list "iL", then how can the list elements fit into that array?
Why line #1 is not generating compilation error or an exception?

[Edit: added code tags]
 
Henry Wong
author
Marshal
Pie
Posts: 20889
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Take a look at the JavaDoc for ArrayList again. The toArray(array) method only returns the original array if the elements fit. If it doesn't, it allocates a new array.

Henry
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic