Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Collection prob

 
Debajit Paul
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
add operation is not supported why in case of a List converted from an array?
 
Campbell Ritchie
Sheriff
Pie
Posts: 49776
69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Presumably the idea is to maintain a List which mimics the array. You can probably set elements, but can't add them.

Have you read the API documentation for java.util.Arrays#asList? It says changes "write through," so you would overflow the size of the array.
 
Debajit Paul
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
when we convert list to an array....we can perform add operation on the list and it can overflow the size of the array but in case of array to list why can't we perform add operation on the list?
 
Campbell Ritchie
Sheriff
Pie
Posts: 49776
69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Back to the API: It says it creates a new array. Separate objects. At least that is how I read it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic