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 Review Arrays

nazim khan
nazim khan
1,409 Points

Confused with An array's length is immutable, it cannot be changed?

Hi Im bit confused with the abbve question since we can change the length of the Array using method

public static <T> T[] copyOf(T[] original, int newLength) can anyone please Explain this to me

1 Answer

Seth Kroger
Seth Kroger
56,413 Points

That doesn't really change the length of an array. It creates a new array with the new length and copies the old array into it. The old array is unchanged. It's the same way Strings are immutable. You can replace a String with an entirely different one but you can't change the content of either.