I want to write a small algorithm.
I'm facing the following issue: I have a String
that can contain digits and the following symbols: -
, (
, )
. I want to parse it, so I can get each symbol and number.
The method I want to write, (getNextToken
) should return the symbols and numbers succesively. For example: getNextToken("(123-456)-12-1")
should return:
- on the first call:
"("
- on the second call:
"123"
- on the third call:
"-"
and so on.
The problem I'm facing is that each numeric part can contain several digits.
I understand that it's not a big deal to write this kind of function, but it is not a "primitive" function. So, does Java have an utilit class to solve this problem?