Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Help with constructor  RSS feed

 
Taheerah Nasai
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I have a
constructor: public Persons(Person[] aList, int aSize) & a
field: private Person[] personList;

how can I 1. Form a Person array of length aSize and put the address of this array into personList. 2. Then use the constructor to copy the first aSize persons from aList onto the newly created array.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
see if you can follow along with this
(I scrapped 'aSize' in the constructor)

 
David Harkness
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can create an array using the new operator, just like classes:This creates an array of twelve ints, each initialized to the default value zero. You can use System.arraycopy() to copy a range of values from one array to another.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!