Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java Java Data Structures Organizing Data Arrays

jay ang
PLUS
jay ang
Courses Plus Student 679 Points

System.arraycopy(); the last '2'?

in the System.arraycopy(fruit, 0, biggerfruit, 0 , 2); what does the '2' means? (the last one)

2 Answers

andren
andren
28,558 Points

The last argument is the length. More simply put it is the number of items you want to copy from one array to the other.

Robert Stamate
Robert Stamate
13,227 Points

As andren said the last argument is length. In order to make it more understandable I got by this: System.arraycopy(fruit, 0, biggerfruit, 0 , fruit.lenth); // Instead of two (2) I use the current array length;

And if I use the java.util.Arrays I got like this: fruit = Arrays.copyOf(fruit, fruit.length + 1); // and it will always add me one more spot in my Array at the end;