- 1
String tokens in JAVA
String str = scan.nextLine(); String delims = "[ !,?.\\_'@]+"; String[] tokens = str.split(delims); I wants to generate tokens that are present in any given String. But I wants to know how this statement will work. String delims = "[ !,?.\\_'@]+"; For example : Sample Input He is a very very good boy, isn't he? Output : He is a very very good boy isn t he And as you can see in the given string [boy, ] after boy , and space both are together so there should not be 2 tokens? If no then how it's working let me know someone
1 Answer
0
this is list of chars which can be used for assembly delimiter (included space as first char)
!,?.\\_'@
next construct means:
take one or more chars from this list,
(and these can be combined to make possible delimiter)
[]+
so comma and space together is one delimiter