In this video we'll conclude on sequences of characters and see other computations that are possible on sequences of characters. We can individually access the characters of a sequence of characters. For example, the instruction line chaine.charAt(index), with index in argument, will return the character of index 'index' of the sequence 'chaine'. The instruction line chaine.indexOf with a character in argument returns the position of the first occurrence of the character 'caractère', that is the character passed as an argument in 'chaine' and will return -1 if 'caractere' isn't in 'chaine'. We also have the function length, which means that we can write chaine1.length() with parenthesis and it will return the length of the sequence, the number of characters in the sequence. Careful, careful! There's a pair of parenthesis. So it's different than arrays, in this case. For example, here I declare a variable s1 that will reference a sequence of characters 'abcmbx'. When I execute this declaration and initialization of the variable 'longueur', the variable 'longueur' will contain the number of characters of s1, that is 6. This declaration declare a variable c1 that will be initialized to the character of index 0 of the sequence s1, which is this 'a'. So c1 will contain the character 'a'. In this declaration of c2 I put the character of s1 that's at the index 'longueur - 1'. 'longueur' contains 6, so 'longueur - 1' is 5. And the character of index 5 is 0, 1, 2, 3, 4, 5. That's the last character of the sequence s1. And finally, the declaration of the variable i will put in i the index of the character b starting from the left in the sequence s1. So s1 is this sequence. 'b', the first 'b' is at the index 1. And therefore i will be initialized with the value 1. So be careful, the characters are numbered like the elements of an array, they begin at zero. At this point, we can do a quiz. In your opinion, what does this code print when we execute it? Take your time to execute the code step by step. I'll let you think about it. So the variable 'essai' is initialized with the sequence "essai". The variable 'test' is initialized with the empty sequence. We enter this for-loop, where i will vary from 1 to 3. During the first round of the loop, we'll execute this assignment. For the moment test is the empty sequence and we concatenate with it the character that is in 'essai' at the index of the value of this expression. i has the value 1, so 6 minus 2 times i is 4. We'll therefore consider the character of index 4 of 'essai'. That is 0, 1, 2, 3, 4, all have the value 'i'. We'll concatenate this character 'i' with the empty sequence and obtain i and put the result in 'test'. 'test' will now point to the sequence "i". Let's then move on to this instruction line, that will concatenate the character of index i of the sequence of characters 'essai'. i has the value 1, the character is the character 's'. We'll concatenate it with the sequence of characters contained in 'test', which is simply "i". The result of the concatenation is the sequence "si", we'll put "si" here. We then come back to the start of the for-loop. i now has the value 2. We execute this assignment. 'test' now has the value "si". This character is the character of index 2 in 'essai'. The character of index 2 is (zero, one, two). It's an 's', that we'll concatenate with the sequence "si" and we'll obtain "sis", that we'll assign to the variable 'test' to obtain this. Let's move on to the second assignment. essai.charAt(i). As i has the value 2, it's this 's' that we'll concatenate with the sequence that corresponds to 'test'. That is "sis", and we'll obtain "ssis" which we'll put in 'test'. We'll now return a last time here, with i that has the value 3. 'test' has the value "ssis" and we'll concatenate this character, so the character of index 0, in the sequence 'essai', that's this 'e' here. We'll put the result in the sequence 'test', so we'll put "ssise" in 'test'. We now move on to the assignment. essai.charAt(i) : i has the value 3, it's the character of index 3 of 'essai', that's 0, 1, 2, 3, so 'a'. We'll concatenate that with what 'test' contains, that is "ssise", and get the sequence of characters "assise". 'test' will now therefore point to the sequence "assise". We exit the loop, as i has the value 3. We get to this print instruction that will simply print assise. Just a word about inputs/outputs with characters. It turns out that there doesn't exist a function nextChar() in the Scanner class. To get a character using this class, you have to first declare a Scanner, as usual. Then you have to read a line by using the function nextLine() applied to the instance of Scanner type and put the result in a variable of String type that I named s. Then take the first character of this sequence s with the function charAt(), passing it the index 0 as an argument. So here in 'c', we'll obtain the first character that the user will have input at this moment. A String literal, entered by the user during a read instruction line for example with a Scanner, doesn't belong to the String literal pool. For it to be part of it, you have to explicitly put it in, with the help of the <i>intern</i> function. Let's consider this example where I begin by declaring a Scanner s that will allow me to read what the user inputs on the keyboard. Here I declare a variable 'response' of type sequence of characters and I have a do-while loop that will stop when the user enters oui (= yes) as an answer. This 'oui' is a sequence of characters that's in the String literal pool. Now let's continue with the code. Let's suppose that I read what the user inputs on the keyboard, and that I put the result in the variable 'response'. I'll get something like this. Let's suppose that he has already input "oui", because he wants to exit the loop. But if you followed what I've just said, this "oui" isn't in the String literal pool, which means that this "oui" is different from this "oui". This print will indeed display 'oui' for 'response'. On the other side, this test won't do what I want, as here I'm testing the references. 'response' contains a reference to this "oui" and this "oui" isn't stored at the same reference, as it's in the String literal pool. So in this test, the condition will be false, even if 'response' contains "oui". I'll add the call to the 'intern' function, that I had hidden here. What happens in this case? When we execute this new instruction line, the 'oui' contained in 'response' will be put in the String literal pool. It turns out that there already is a "oui" in the String literal pool. What will happen is that now 'response' will contain a reference to this "oui". And this link is lost. This print instruction line will display a 'oui', like before. This is the 'oui' that will be printed. And now, when we do this test. We are still testing the references. That is the reference contained in 'response' with the reference of this "oui", which is in the String literal pool. But as this reference points to the "oui" of the String literal pool, it's the same reference and this test will this time be true. This is due to the 'intern' function. We saw there exists a number of functions specific to String, like the 'equals' function, or the 'length' function. All these functions follow the same syntax, we begin with the name of a variable of String type. Then the function's name, with the 'point' character between them, and followed by the arguments that the function needs. These functions are called methods in Java. They always produce a new sequence of characters. The sequences of characters involved in this use aren't modified. For example, we have the function 'replace' that can be applied to a variable of String type, for example 'chaine' here. It awaits two characters to be able to function. This 'replace' function will replace the character 'char1' of 'chaine' with the character 'char2'. For example, if I have a sequence 'exemple' initialized with 'abracadabra', and that I call the 'replace' function by passing it the character 'a' as first value, and the character '*' as second value. This function will create a new sequence of characters where it will have replaced the 'a's of 'abracadabra' with a star. And that's exactly what I obtain here. Note that the sequence 'exemple' still contains the original sequence 'abracadabra'. Another function is 'substring'. It's also applied on a variable of String type, like the 'chaine' variable, and awaits two positions to operate. The positions of two characters. This function will extract a substring from the variable given here. So for example, here I declare a variable 'exemple' initialized with the sequence "anticonstitutionnel". In this assignment, I execute the function 'substring' on this sequence by passing it the values 4 and 16. That means that I'll extract the sequence of characters that begins at the characters of index 4. 'a' is the character of index 0. 1, 2, 3, 4, so it's this 'c' here. The character of index 16 is this 'n'. But the last character is not included. So I'll stop here. And this function will return the sequence that is here, "constitution", which will be used to initialize the variable 'racineMot'. Voilà, that's all we'll see for the String type.