given a number (user input) 01111000
I want to extract the individual digits 0,1,1,1.....
Is it possible using stringtokenizer, I have tried empty strings, "//d" , "?" but it doesn't work...
specific to stringtokenizer only
given a number (user input) 01111000
I want to extract the individual digits 0,1,1,1.....
Is it possible using stringtokenizer, I have tried empty strings, "//d" , "?" but it doesn't work...
specific to stringtokenizer only
String s = "01111000";
System.out.println(java.util.Arrays.toString(s.split("(?<=\\G.)")));
Which produces
[0,1,1,1,1,0,0,0]
Why Tokenizer
? Use a loop
and a charAt(position)
.
If you still want Tokenizer
, use this trick:
String number = "01111000010".replaceAll("", " ");
StringTokenizer tokens = new StringTokenizer(number," ");