Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Well done!
You have completed Java Arrays!
You have completed Java Arrays!
Preview
An array's length is immutable, meaning it cannot be changed. If you want to add or remove, you need to declare a new array and copy into it. Don't worry you won't be doing this too much.
Learn More
Example ArrayList code
// This is coming from the Java Collection Framework
import java.util.List;
import java.util.ArrayList;
// This is using Generic syntax, we'll get to it...
List<String> friends = new ArrayList<>();
friends.add("Brian"); // adds "Brian" to the friends list
friends.size(); // returns 1
friends.contains("Brian"); // returns true
friends.remove("Brian");
friends.size() // returns 0
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
power of arrays, it's time
to look at some of their limitations.
0:00
Have we been dealing with arrays
where we either know all of the items
0:00
at declaration time, or at least know
how many will be there eventually.
0:04
In reality,
that's not always the case, is it?
0:08
I'm sure you can imagine programs
where we're taking input from a user,
0:11
and they want to either add
or remove elements from the array.
0:16
If you recall,
when we first started talking about this
0:19
fancy new data structure, we talked
about how its length is immutable.
0:22
Now remember,
that means it can't be changed.
0:26
The reason for this immutability
was because the declaration
0:29
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up