5.10 Parsing values
In this video we will convert a character string into another type of data such as int for example! As you can see, I created a new project. So we come here and we write “String numberAsString = “2018”. We will display the number…. So this is a string and not a number, the goal is to convert it a number but first we will launch the program and as we can see the string is equal 2021 now we will convert it into a number. There is a method to convert a string to a number. Int number = Integer.parseInt(the string variable) Now when we add the integer 1 to the string, java will automatically convert the number 1 into a string and then concatenate these two strings so that the numeric string will now have the value 2, it’s to say the value of the string will be 2021 and 1 behind or that’s not what we want. But using “number” =+ 1 we increment “number by 1” so number will be 2022.