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