• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

toArray question

 
Paul Stat
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm confused how the following code works, AND prints out all 7 elements of the original collection? I would of thought there would been an excepton at the very least?

 
Senthil Kumaran
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i suggest you to re look the toarray() and aslist() methods again,.,
 
Paul Stat
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Senthil Kumaran wrote: i suggest you to re look the toarray() and aslist() methods again,.,


enlighten me
 
Henry Wong
author
Marshal
Pie
Posts: 21417
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Stat wrote:
Senthil Kumaran wrote: i suggest you to re look the toarray() and aslist() methods again,.,


enlighten me


No offense, but it takes less than a minute to look it up yourself. Why do we need enlighten you?

http://java.sun.com/j2se/1.5.0/docs/api/java/util/List.html

Henry
 
Paul Stat
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Henry Wong wrote:
Paul Stat wrote:
Senthil Kumaran wrote: i suggest you to re look the toarray() and aslist() methods again,.,


enlighten me


No offense, but it takes less than a minute to look it up yourself. Why do we need enlighten you?

http://java.sun.com/j2se/1.5.0/docs/api/java/util/List.html

Henry


Ok fine so it


Returns an array containing all of the elements in this list in proper sequence


But what happens to the original String[] array, is it just subject to the garbage collector?
 
Ankit Garg
Sheriff
Posts: 9528
32
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Stat wrote:
But what happens to the original String[] array, is it just subject to the garbage collector?


If you are talking about this

String[] sa = new String[3]; // intialise sa to accept 3 String objects

Then yes that string array will be eligible for GC. This is the related statement from the documentation

If the list fits in the specified array, it is returned therein. Otherwise, a new array is allocated with the runtime type of the specified array and the size of this list.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic