I'm wondering how to do something only if Integer.parseInt(whatever) doesn't fail.
More specifically I have a jTextArea of user specified values seperated by line breaks.
I want to check each line to see if can be converted to an int.
Figured something like this, but it doesn't work:
for(int i = 0; i < worlds.jTextArea1.getLineCount(); i++){
if(Integer.parseInt(worlds.jTextArea1.getText(worlds.jTextArea1.getLineStartOffset(i),worlds.jTextArea1.getLineEndOffset(i)) != (null))){}
}
Any help appreciated.
You can use the try..catch statement in java, to capture an exception that may arise from Integer.parseInt().
Example:
keep in mind that I meant ParseException as the proper type of exception for the specific case