---
title: "How to convert numeric String to int in Java?"  
description: "How to convert numeric String to int in Java?"  
author: "Ronan Jone"  
published: 2018-02-27  
canonical: https://answers.mindstick.com/qa/35073/how-to-convert-numeric-string-to-int-in-java  
category: "programming"  
reading_time: 1 minute  

---

# How to convert numeric String to int in Java?

## Answers

### Answer by Arti Mishra

For converting a numeric [string](https://www.mindstick.com/articles/1717/string-string-builder-and-string-buffer-in-java) to an int using the parseInt [method](https://www.mindstick.com/articles/23411/the-most-effective-method-to-find-the-perfect-small-business-phone-system-for-your-business) of the [Java](https://www.mindstick.com/articles/1702/introduction-to-java) [Integer](https://www.mindstick.com/forum/1000/char-char-int-why) [class](https://www.mindstick.com/articles/12089/arrays-in-java-determining-class-of-an-array-part-8). The parseInt method converts the String to an int, and throws a [NumberFormatException](https://www.mindstick.com/forum/159246/how-to-handle-the-numberformatexception-in-java) if the string can’t be converted to an int type. Example for converting numeric [string to int](https://www.mindstick.com/forum/23195/converting-string-to-int-in-java) in java - \

| [public](https://www.mindstick.com/interview/757/why-main-in-java-is-declared-as-public-static-void-main) class StringToIntExample \ { \ public [static](https://www.mindstick.com/articles/12098/the-static-keyword-the-static-methods) void main (String[] args) \ { \ String s = "100"; // Numeric String\ try \ { \ \ int i = Integer.parseInt(s.trim()); \ System.out.println("int i = " + i); \ } \ [catch](https://www.mindstick.com/interview/867/can-multiple-catch-blocks-be-executed) (NumberFormatException e) \ { \ System.out.println("NumberFormatException: " + e.getMessage()); \ } \ } \ } |
| --- |

\


---

Original Source: https://answers.mindstick.com/qa/35073/how-to-convert-numeric-string-to-int-in-java

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
