Search code examples
javaregexstringtokenizestringtokenizer

How not count blank spaces in StringTokenizer


I have this line

StringTokenizer tk=new StringTokenizer (b=10," =",true);

my output is

b
=
10

and this perfect but again if my line is this

StringTokenizer tk=new StringTokenizer (DEFI b=10," =",true);

And my output is

DEFI

b
=
10

I don't wanna include that empty o white space in the ST, How can I avoid including the white space cause I want this kind of output

DEFI
b
=
10

Solution

  • If you can, I suggest using String.split() method:

    String[] tokens = "DEFI b=10".split("(\\s|(?=\\=)|(?<=\\=))");