1 00:00:00,000 --> 00:00:09,385 [MUSIC] 2 00:00:09,385 --> 00:00:14,610 In the past few courses we learned about inheritance, interfaces, and generics. 3 00:00:14,610 --> 00:00:19,147 And when Java launched in 1995, that was the end of the story. 4 00:00:19,147 --> 00:00:23,290 However, it didn't take long before developers wanted more. 5 00:00:23,290 --> 00:00:26,587 One place Java seemed to be lacking was with arrays. 6 00:00:26,587 --> 00:00:29,665 At this point, if we have a collection of objects, 7 00:00:29,665 --> 00:00:33,310 the only way we can store them is with an array. 8 00:00:33,310 --> 00:00:36,306 And arrays work great for things that have a fixed size, 9 00:00:36,306 --> 00:00:40,141 like the number of months in a year or number of squares on a chess board. 10 00:00:40,141 --> 00:00:44,550 But arrays don't work so well when the size of the collection changes. 11 00:00:44,550 --> 00:00:47,756 For example, let's look at the checkout line at the grocery. 12 00:00:47,756 --> 00:00:50,750 Right now, there's only a couple of people in line. 13 00:00:50,750 --> 00:00:54,881 But if we jump forward to the holidays, there's a ton of people here. 14 00:00:54,881 --> 00:00:59,233 So if we wanted to use an array to store all the people in line we'd need to make 15 00:00:59,233 --> 00:01:02,420 the array big enough to handle the holidays. 16 00:01:02,420 --> 00:01:06,739 Which means most of the year, our array would just be taking up space. 17 00:01:06,739 --> 00:01:11,210 It'd be as if the grocery left their queues up all year. 18 00:01:11,210 --> 00:01:16,240 To fix this problem, in 1998 we got the Java Collections framework. 19 00:01:16,240 --> 00:01:19,303 A set of classes and interfaces which give us a lot 20 00:01:19,303 --> 00:01:23,860 more flexibility in how we store collections of objects. 21 00:01:23,860 --> 00:01:28,470 Now the Java Collections framework is made up of a lot of classes and interfaces. 22 00:01:28,470 --> 00:01:29,982 But for the most part, 23 00:01:29,982 --> 00:01:36,320 there's only two types of collection that we'll use frequently, lists and maps. 24 00:01:36,320 --> 00:01:41,557 We'll save maps for a later of course but right now, let's focus on lists. 25 00:01:41,557 --> 00:01:46,290 In Java, a list is pretty much just a more flexible array. 26 00:01:46,290 --> 00:01:50,730 Like an array, the items are indexed and we can access them by their index. 27 00:01:50,730 --> 00:01:56,880 But unlike an array, with a list we can add or remove items anywhere we like. 28 00:01:56,880 --> 00:02:01,355 We also get a few helpful methods, like contains() which returns a Boolean telling 29 00:02:01,355 --> 00:02:03,293 us if a list contains a certain item. 30 00:02:03,293 --> 00:02:07,147 And indexOf() which searches the list for an item and 31 00:02:07,147 --> 00:02:12,700 returns the index of that item, if it's found, or negative one if it's not. 32 00:02:13,750 --> 00:02:16,673 In addition to being a more flexible version of arrays, 33 00:02:16,673 --> 00:02:20,478 lists also give us a bunch of methods to help deal with groups of objects. 34 00:02:20,478 --> 00:02:26,075 In fact, in most cases you'll probably end up using a list instead of an array. 35 00:02:26,075 --> 00:02:28,520 Let's see how to use a list in the next video.