I have a complex string and I just need to get each and every char in this string one by one. Here what I did, but at one place I am getting both /( I know what because there is a no delimiter between them. How can I overcome this?
Hear is my string : 3 + 4 * 2 / ( 1 - 5 )
My code:
StringTokenizer tokenizer = new StringTokenizer(mathExpression , "+-x/()"); StringTokenizer tokenizer2 = new StringTokenizer(mathExpression , "123456789"); while (tokenizer.hasMoreElements()) { System.out.println(tokenizer.nextToken()); } while (tokenizer2.hasMoreElements()) { System.out.println(tokenizer2.nextToken()); } Output :
3 4 2 1 5 + x /( - )