Hi, we're gonna show an example of how the array list structure works. We'll show code that keeps track of how many times each word in a file occurs. The file or it could be a URL, could be a large file, like text from Shakespeare's Romeo and Juliet, or like the sayings of Confucius. We don't know how many different words there are before we start reading the file. So we can't easily use an array. Instead we'll use two ArrayList structures. One that holds strings and one that holds integer values. We'll need integer instead of int. We'll explain why. The kth value of the array list, whose name is myFreqs, will store an integer. The number of occurrences of the kth value in the instance variable array list, myWords. The names are names of instance variables that we'll see in the code. As shown here we see two occurrences of the with a string and an integer stored in the location with index zero in the two different array lists. Similarly there were three occurrences of the word dog, and one occurrence of the word green. Let's write code. We've got a class, WordFrequencies. I'm gonna open it up, and take a look to see how it works. And one way we can easily see how it works, before we look at the code, is simply to run it. I've created an instance of it on my object work bench. I'm going to right click and run the tester method. I'm gonna open the file romeo.txt, the entire text of Shakespeare's Romeo and Juliet. And I can see that there were 5,895 unique words. What I like to do with ArrayList is count how many times each word occurs. So I'll find out how many times the occurs Montague, Capulet, all the words from Romeo and Juliet. Just going through this code very quickly to highlight the key features before I add the counting. I have an instance variable, myWords, which is initialized to be able to hold strings in the constructor. In tester, I call the function findUnique. Which creates a file resource and because it had no parameters that allowed me to open up any file I wanted. It looks over every word, converts each word to lowercase. If the word has never been seen before, which I find out by using the array list method .indexOf which is a method whose same name we've seen in the string class. If it has never been seen, I add it to my words. Now what I want to do is have a parallel array. I will call it myFreqs, for my frequencies. So I need another instance variable. This has to store integer values, and unfortunately with array lists in Java, I must use integer. You've seen this before with integer.parseint. Similar to the class Double.parseDouble, I'll explain this as I go, I need to store integers. I'm going to create a place for it. I'm going to initialize that in the constructor to a new ArrayList of Integer values. And then If I've never seen the word before, that means this is the first occurrence. So, I'm gonna add to the end of the array list the value 1. This is just like the idea of, the first time you see a word, it's occurred once. But, if I've seen it before, this is in my else statement. If I’ve seen it before I know where it is because index tells me. So what I’m going to do is find the value that’s in myFreqs, this is the number of times it’s already occurred. I can get this value using the get method and then I can set the value. In myFreqs, to value +1. So, let me make clear what I've just done there. I've accessed the value at the location specified by index, which was returned to me by the dot index of method. And the idea here is that if the word the, occurs in location 500 of my words, the frequency, or number of times that occurs is in location 500 of myFreqs. They match up exactly. This will, I hope, compile. Cannot find myFreqs. So, I've looked up here and I can see myFreqs, myFreqs myFreqs, that's because I forgot to say set, the name of the method to set the value is set. Now I'm ready to run it. But I haven't printed any values. After I've printed them, so after I've tested them all and found them I will literally print every single word and how many times it occurs. So I'm gonna use the standard four loop that loops over array values or array list values. Size is the method that tells me how many there are. And I'm going to print The number of occurrences which is in myFreqs, a tap character and then the word itself. That compiled I'll create a new one by right clicking and creating a new object. And then I'm going to run the tester method on this object by right clicking. There's the right click, run tester. Let's count romeo. And you can see how many times different words have occurred in Romeo. For example, the has occurred 677 times, Romeo 48 and Juliet 23. Another word that occurs often is Juliet with a period. I haven't taken into account punctuation at all. And from occurs 86 times. Let's make sure that part of the code is clear. I've accessed the value in myFreqs and stored it in the Int value. And then I've set the value at index to value +1 because array lists use integer rather than int, this is a two step process. Find the value and then store the value. That's what we need to do with integer which would be a little bit different than we had with int. We'll see that in a later video. Let's look down here. MyFreqs .get(k) returns the kth value of the frequency array list. And myWords.get(k) returns the corresponding word. The 23rd frequency is the number of times the 23rd word has occurred. Now that you know a little more about array lists, let's write some code.