Android 2.3.3
I have an ArrayList which has both Numbers(in string format) and also words like (and, plus, by, …)
I wish to retrieve numbers only from this ArrayList.
I can get the value using get(index) and convert to number, if it a number that can be converted. If i use a loop to iterate, conversion of words will throw me an exception. So, how do i check, without getting an exception.
Will this work:::
I use a try catch block and when there is an exception, I just write “continue;” in the catch block.
You can try to convert in a
tryblock, and ignore the exception in thecatchblock. (Justcontinuethe loop, like you suggested). It will work.Another method, without making use of exceptions handling;
Determine if a String is an Integer in Java
How to check if a String is numeric in Java
And there are many more.