"N/A"
is not an integer. It must throw NumberFormatException
if you try to parse it to an integer.
Check before parsing or handle Exception
properly.
- Exception Handling
try{ int i = Integer.parseInt(input); } catch(NumberFormatException ex){ // handle your exception ... }
or – Integer pattern matching –
String input=...; String pattern ="-?\\d+"; if(input.matches("-?\\d+")){ // any positive or negetive integer or not! ... }
Related Posts:
- How do I convert a String to an int in Java?
- Java – Convert integer to string [duplicate]
- How can I prevent java.lang.NumberFormatException: For input string: “N/A”?
- Determine if a String is an Integer in Java [duplicate]
- How to format strings in Java
- How to split a string in Java
- How do I compare strings in Java?
- How to convert a char to a String?
- What is the proper way to handle a NumberFormatException when it is expected?
- How to convert/parse from String to char in java?
- Java String Split by “|”
- Convert String to double in Java
- Java String new line
- How can I convert a char to int in Java? [duplicate]
- How to check if a String contains another String in a case insensitive manner in Java?
- Java split string to array [duplicate]
- Java string to date conversion
- What are all the escape characters?
- “int cannot be dereferenced” in Java
- Best way to convert an ArrayList to a string
- How to split a String by space
- String interpolation in Java 14 or 15
- How to remove single character from a String
- How do I limit the number of decimals printed for a double?
- How to parse this string in Java?
- How do I limit the number of decimals printed for a double?
- How to split a string in Java
- Illegal Escape Character “\”
- What does regular expression \\s*,\\s* do?
- How to convert a Binary String to a base 10 integer in Java
- Left Hand Side of an Assignment must be a Variable CharAt
- How to capitalize the first letter of a String in Java?
- catDog string problem at Codingbat.com
- How to check if an int is a null
- Return string Input with parse.string
- What is the difference between String.subString() and String.subSequence()
- How do I apply the for-each loop to every character in a String?
- Java compressing Strings
- Explain the use of a bit vector for determining if all characters are unique
- Convert array of strings into a string in Java
- How to check whether a int is not null or empty?
- How to remove single character from a String
- How to remove single character from a String
- What is Java String interning?
- What is Java String interning?
- Why is there no String.Empty in Java?
- Java split string to array
- Using Enum values as String literals
- What is the difference between Integer and int in Java?
- int cannot be converted to string?
- How to check if my string is equal to null?
- what is Ljava.lang.String;@
- Convert String to int array in java
- java.lang.NumberFormatException: null i
- Converting String Array to an Integer Array
- How to sort an array of objects in Java?
- How to sort an array of objects in Java?
- java.lang.NumberFormatException: empty String
- How to check if a String is numeric in Java
- How to replace a substring of a string
- Converting A String To Hexadecimal In Java
- Immutable class?
- Java, Simplified check if int array contains int
- JAVA Variable declaration not allowed here
- Converting a string to an integer on Android
- Simple way to repeat a string
- Java end of file
- Unclosed Character Literal error
- Java: how to initialize String[]?
- Regular Expressions on Punctuation
- Add String Array to ArrayList
- Java Array Sort descending?
- How to extract a substring using regex
- difference between equals() and hashCode()
- How can I check if a single character appears in a string?
- Java String to SHA1
- Replace a character at a specific index in a string?
- Convert boolean to int in Java
- How to convert a String to CharSequence?
- How do I convert a String to a BigInteger?
- How can I remove a substring from a given String?
- Java get String CompareTo as a comparator object
- How to use regex in String.contains() method in Java
- How to swap String characters in Java?
- Get an OutputStream into a String
- Difference between string object and string literal
- How to convert a String into an ArrayList?
- java: use StringBuilder to insert at the beginning
- How do I get the last character of a string?
- Cannot invoke toString() on the primitive type int
- How to Convert Int to Unsigned Byte and Back
- How to compare character ignoring case in primitive types
- convert string to arraylist
in java - How to insert multiple tabs string in java?
- Append a single character to a string or char array in java?
- String is immutable. What exactly is the meaning?
- Occurrences of substring in a string
- Quotation marks inside a string
- Fastest way to put contents of Set
to a single String with words separated by a whitespace? - How to know if a given string is substring from another string in Java