-2

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

Creative_Cimmons
  • 255
  • 1
  • 2
  • 11

2 Answers2

0
String s = "01111000";
System.out.println(java.util.Arrays.toString(s.split("(?<=\\G.)")));

Which produces

[0,1,1,1,1,0,0,0]
LeDerp
  • 573
  • 2
  • 9
  • 24
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," ");
Jordi Castilla
  • 26,609
  • 8
  • 70
  • 109