 Professor from Department of Electronics from Walton Institute of Technology, Salapur. So today I am here to have a session on converting strings to numbers. After the end of the session student will be able to convert strings to numbers. Let us start the converting strings into numbers which is nothing but integers. There is one person asking for, hey duke, McLean sends me information in XML. So this person's client has sent him information in XML. He says XML contains numbers but when I read the data it is not an integer but it is a string. So this person is facing problem when he read he comes to know the data is in the form of numbers but when he try to understand it it is not number it is in the form of strings. So he want to perform some arithmetic operations on that XML but he is unable to do it. So he is asking his friend duke for the help to convert the strings into the integer. His friend duke says sure buddy I will help you. You will see there is Java which provides a method known as Perseint that will do exactly what you are looking for. So his friend says he is having a method called Perseint in Java which will do the conversion of strings into integer. So let us see how the duke is going to explain the procedure to convert the strings into integer. He says there are two ways to convert strings to integer in Java. First is by using the integer.perseint method and second by using integer.valueOf method. So let us see these two methods in detail one by one. First is string to integer using integer.perseint method. Syntax for this method is you will be requiring second variable which would be of integer where you are going to store the converted integer so integer and the int variable name equal to the you are calling the method now integer.perseint and the string variable name. So let us say you have a string str test that contains a numeric value. So there is a string str is a data type str test is the string variable name equal to in the codes you have hunted. So as a human eye when you see hundred it is a number but it is in the form of string you cannot perform any arithmetic operation on this string. So you need to convert this hundred which is a string into the integer by using the any of the methods. Second is convert the string to integer using the integer value of method. So the syntax is similarly you are requiring one more variable which would be of integer data type integer followed by the integer variable name equal to integer.valueOf and the string variable name. Let us try write a program to convert the given string to integer using the integer perse method. So the given string str test we have seen in the previous slide equal to hundred that hundred is in the form of string. So convert the hundred into the integer run open the command prompt open the notepad you have a program public class you have as integer as the class name the main function public static wide main string args now str there is nothing but the string data type and the variable name is string test equal to hundred just declare the string value as hundred and store in the variable as str test which is the variable name. Now try to perform arithmetic operation on this first let us see what error we are going to get system dot out dot print l n str test divide by four. So try to perform arithmetic operation divide by four on this string which is hundred let us see what type of error we can get save the file with the class name integer dot java go back to the command prompt change the directory to the file where it is stored my file is stored on desktop. So now call the java compiler javac my file name is integer dot javac what error you can get bad operand type of binary operation. So you cannot perform binary operation on strings you need to convert the string into integer. So first operand type is string second is integer and it will give you error of bad operand for the binary operation. So what change you will be requiring convert this string into integer. So you will be requiring one more variable of integer data type and have it as variable name as test. So the syntax is capital integer dot first int of the variable str test you need to perform arithmetic operation on the integer type. So change the variable to test divide by four. So integer dot first int of the string this is the syntax. So save the file control s go to the command prompt run the java compiler java string integer dot java see now bytecode is successfully generated there is no type of bad operand because we have converted the string and then into the integer the java integer dot integer. So you can get 25 so 100 divide by 25 previously the 100 was a string so you were not able to perform the binary operation. Now we have converted the 100 which is string into integer using integer pulse method which is 100 is converted into integer. Now it becomes 100 number so 100 divide by 4 is 25. Let us have a second program write a program to convert the given string to integer using the integer value of method. So open the notepad let me have the program let me edit on the same file. Now the string str test same string I am going to have 100 ok I am going to convert using the integer value of method. So you will be requiring integer data type int test equal to ok. So integer dot value of this is my syntax and here you will be having the string variable so which is str test ok. Now what you are going to print system.out.println and you are going to perform the arithmetic operation on the test variable now. So tst is my integer variable and divide by 4 save the file ctrl s. Open the command from java c integer dot java yes divide code is successfully generated now java integer you are going to run the file. So you can get 25 as the output the same output you will get because you are going to perform the same operation but here you are using the integer value of method. Think and write what is input parameter for string value of method. So if you are not able pause the video and answer the question if you are unable to answer the question rewind my video and try to answer the question what is the input parameter for the string value method the answer to the question is string. If you are unable rewind my video and try to answer the question the input parameter for the string value of method is nothing but string parameter the references are taken from java a beginners guide code java 2 volume 1 fundamentals java 2 the complete reference guide thank you.