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
Let's talk about what we're going to talk about in this course.
Prerequisites
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
[MUSIC]
0:00
Hi, I'm Craig and I'm a developer.
0:04
In this course,
we are gonna talk all about arrays.
0:07
Arrays are container objects that can
be used to store multiple values.
0:10
If arrays are a new concept to you,
you're in the right place.
0:15
We'll talk all about what they are,
how to create them, as well as why and
0:18
when you should use them.
0:22
But, before we get started
please double check that you've
0:24
completed the prerequisites.
0:27
I'm gonna assume that you have
a handle on some Java already and
0:29
I just wanna make sure that
we're all on the same page.
0:31
That reminds me, there are teacher
notes attached each video, and
0:35
you can very easily speed me up or slow
me down, whatever works best for you, and
0:38
don't forget that
the Tree House Community is awesome, and
0:43
you should reach out to your fellow
students whenever you have a question.
0:46
You should also check it out and see if
you can help answer some of the questions.
0:49
Nothing helps to make your learning
like answering a question.
0:53
If you've ever used the string,
you've already witnessed arrays.
0:56
A string is really just
an array of characters, right?
1:00
Each item, or element,
of the array is a single character.
1:03
Now the creation of that underlying array
has been abstracted away from you so
1:07
you don't really need to think about it.
1:11
But under the covers, that is exactly what
is happening when you declare a string.
1:13
And characters aren't the only type that
can benefit from this container object.
1:17
In fact,
any data type can be used in an array.
1:21
The limitation is that all elements of the
array have to be of the same type, right?
1:25
You can't mix strings with integers and
you can't mix floats with Booleans and
1:30
things like that.
1:33
Okay, for
1:35
instance, lets imagine you're writing an
application to keep track of golf scores.
1:36
If you're unaware of how golf works,
there's typically 18 holes and
1:40
you keep track of how many times you
try to hit that tiny little ball
1:44
in each of those tiny little holes.
1:47
So you could definitely create
a separate variable for each hole.
1:50
But, wouldn't it be nice to store
the scores in a single variable?
1:53
Well you can.
1:58
What you do is you just
make an array of integers,
2:00
where each element would
represent the score for each hole.
2:03
You could then use that array
to print out each of the scores.
2:06
Arrays are built to let you
process their elements as a group.
2:09
You could process each of the elements or
loop over them and print them out.
2:13
You can also find the most difficult hole,
or the worst, or the average.
2:17
You can also pass the array around
just like any other variable.
2:21
Could you imaging having to pass all those
golf scores as individual variables?
2:25
Arrays to the rescue.
2:29
Now there are a couple of ways to
create arrays, so let's get started.
2:31
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