Next: Equality testing. Up: Strings. Previous: The String class.


String-related methods

The Integer.parseInt() method

Another useful method to know about is the parseInt() class method in the Integer class. It takes a String as a parameter and returns the corresponding integer value.

int value = Integer.parseInt("563");
This puts the value 563 into the value variable.

There's also a Double.parseDouble() method that works the same way, except for double values.

The IO.readString() and IO.readLine() methods

The IO class provides two ways of reading a string from the user. The IO.readLine() method returns a string containing all the letters of a line, while the IO.readString() method returns the next word. (Actually, IO.readString() returns the next string of non-whitespace characters it finds - so the word can contain a mix of letters, digits, and punctuation.)


Next: Equality testing. Up: Strings. Previous: The String class.