1 00:00:00,000 --> 00:00:04,884 [MUSIC] 2 00:00:04,884 --> 00:00:07,300 Hi, I'm Craig and I'm a developer. 3 00:00:07,300 --> 00:00:10,660 In this course, we are gonna talk all about arrays. 4 00:00:10,660 --> 00:00:15,050 Arrays are container objects that can be used to store multiple values. 5 00:00:15,050 --> 00:00:18,300 If arrays are a new concept to you, you're in the right place. 6 00:00:18,300 --> 00:00:22,290 We'll talk all about what they are, how to create them, as well as why and 7 00:00:22,290 --> 00:00:24,240 when you should use them. 8 00:00:24,240 --> 00:00:27,150 But, before we get started please double check that you've 9 00:00:27,150 --> 00:00:29,162 completed the prerequisites. 10 00:00:29,162 --> 00:00:31,760 I'm gonna assume that you have a handle on some Java already and 11 00:00:31,760 --> 00:00:33,920 I just wanna make sure that we're all on the same page. 12 00:00:35,290 --> 00:00:38,945 That reminds me, there are teacher notes attached each video, and 13 00:00:38,945 --> 00:00:43,815 you can very easily speed me up or slow me down, whatever works best for you, and 14 00:00:43,815 --> 00:00:46,545 don't forget that the Tree House Community is awesome, and 15 00:00:46,545 --> 00:00:49,735 you should reach out to your fellow students whenever you have a question. 16 00:00:49,735 --> 00:00:53,375 You should also check it out and see if you can help answer some of the questions. 17 00:00:53,375 --> 00:00:56,730 Nothing helps to make your learning like answering a question. 18 00:00:56,730 --> 00:01:00,210 If you've ever used the string, you've already witnessed arrays. 19 00:01:00,210 --> 00:01:03,460 A string is really just an array of characters, right? 20 00:01:03,460 --> 00:01:07,630 Each item, or element, of the array is a single character. 21 00:01:07,630 --> 00:01:11,390 Now the creation of that underlying array has been abstracted away from you so 22 00:01:11,390 --> 00:01:13,400 you don't really need to think about it. 23 00:01:13,400 --> 00:01:16,640 But under the covers, that is exactly what is happening when you declare a string. 24 00:01:17,660 --> 00:01:21,890 And characters aren't the only type that can benefit from this container object. 25 00:01:21,890 --> 00:01:25,390 In fact, any data type can be used in an array. 26 00:01:25,390 --> 00:01:30,440 The limitation is that all elements of the array have to be of the same type, right? 27 00:01:30,440 --> 00:01:33,840 You can't mix strings with integers and you can't mix floats with Booleans and 28 00:01:33,840 --> 00:01:34,350 things like that. 29 00:01:35,510 --> 00:01:36,060 Okay, for 30 00:01:36,060 --> 00:01:40,460 instance, lets imagine you're writing an application to keep track of golf scores. 31 00:01:40,460 --> 00:01:44,390 If you're unaware of how golf works, there's typically 18 holes and 32 00:01:44,390 --> 00:01:47,440 you keep track of how many times you try to hit that tiny little ball 33 00:01:47,440 --> 00:01:49,090 in each of those tiny little holes. 34 00:01:50,110 --> 00:01:53,490 So you could definitely create a separate variable for each hole. 35 00:01:53,490 --> 00:01:58,670 But, wouldn't it be nice to store the scores in a single variable? 36 00:01:58,670 --> 00:02:00,060 Well you can. 37 00:02:00,060 --> 00:02:03,050 What you do is you just make an array of integers, 38 00:02:03,050 --> 00:02:06,810 where each element would represent the score for each hole. 39 00:02:06,810 --> 00:02:09,610 You could then use that array to print out each of the scores. 40 00:02:09,610 --> 00:02:13,150 Arrays are built to let you process their elements as a group. 41 00:02:13,150 --> 00:02:17,100 You could process each of the elements or loop over them and print them out. 42 00:02:17,100 --> 00:02:20,600 You can also find the most difficult hole, or the worst, or the average. 43 00:02:21,680 --> 00:02:25,182 You can also pass the array around just like any other variable. 44 00:02:25,182 --> 00:02:29,610 Could you imaging having to pass all those golf scores as individual variables? 45 00:02:29,610 --> 00:02:30,660 Arrays to the rescue. 46 00:02:31,800 --> 00:02:34,720 Now there are a couple of ways to create arrays, so let's get started.