Convert String to Integer

So I made a little sketch to show you what I think it is you are asking about:

String word, number; 

void setup()
 {
   size(100,100);   
 }
 
 void draw()
 { 
   word = "hello";
   number = "123";
   mixed = "hello123";
  
  //next two lines will not work, you will get a NumberFormat Exception
  System.out.println("Let's try to convert this string that is only words to an int: "+Integer.valueOf(word));
  System.out.println("Let's try to convert this string that is both  to an int: "+Integer.valueOf(mixed));
 //This will work
  System.out.println("Let's try to convert this string that is only numbers to an int: "+Integer.valueOf(number));


  }

These lines of code will not work:

System.out.println("Let's try to convert this string that is only words to an int: "+Integer.valueOf(word));

System.out.println("Let's try to convert this string that is only words to an int: "+Integer.valueOf(mixed));

Because the variables word and mixed contain letters, they will not be converted to ints. But because number is a pure number of 123, it will be converted to an int. Furthermore, you can make a new int, and set it like this:

int newNumber = Integer.valueOf(number);

Hopefully this helps,

EnhancedLoop7