if(str.contains("final"))
{
id = Integer.parseInt(str.substring(18, str.length() - 6));
}
System.out.println(id);
This line of code id = Integer.parseInt(str.substring(18, str.length() - 6));
I got the output as “final year” but it throws an illegalnumberformat exception
For input string: ” final Year”
at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at Product.main(Product.java:47)
How to solve this issue?
I have a text file which has both string and int in it like
final year
93
93
90
91.
In this input given,I need to find the “final year” string and display the count of the number’s below it without repetition.How can I do that
Make sure what you pass into Integer.parseInt() is an int or a String.
If it is a String, make sure it is in numeric format (ie: “2” is okay but “two” is not)