• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

toArray question

 
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?

 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Senthil Kumaran wrote: i suggest you to re look the toarray() and aslist() methods again,.,



enlighten me
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Sheriff
Posts: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

reply
    Bookmark Topic Watch Topic
  • New Topic