HOME > System software > Java: Convert String To Integer - How It Works

Java: Convert string to integer - how it works

In programming there are some cases where certain values are entered, requested or stored. However, the problem with Java is that you cannot associate certain values with certain data types. For this reason, strings consisting of numbers are often converted to integers to be used thereupon.

Java: Convert string to integer - this is how it works

Converting string to another data type is quite easy. In Java, there is a ready-made function for this.
  1. To convert a string to an integer, you need the Static method Integer.parseInt(String s).
  2. This method converts a string consisting of digits to an integer.
  3. Within the method, the string with the digits must be passed as argument and then executed for the string to be converted.
  4. Note, however, that only integers may be contained within the string and that there is at most one plus or minus sign at the beginning.
  5. Sollte die Zeichenkette unzulässige Zeichen enthalten, wird beim Ausführen der Methode eine Exception ausgelöst.

Java: String in ein Integer Objekt umwandeln

  1. Neben der direkten Umwandlung eines Strings in einen Integer können Sie die Zeichenkette auch in ein Integer Objekt umwandeln.
  2. In diesem Fall kann mit dem Inhalt des Objektes wie mit anderen Objekten in Java umgegangen werden.
  3. Dazu nutzen Sie die Methode Integer.valueOf(String s) und übergeben im Argument wie zuvor auch den entsprechenden String.

By Prentiss Ciolli

Google Chrome: How to turn push notifications on and off :: PlayStation 5 pre-order: Is it possible - and when? All info
USEFUL LINKS