String tokens in JAVA | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
- 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

26th Apr 2022, 4:56 AM
Rgodella
Rgodella - avatar
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
26th Apr 2022, 7:07 AM
zemiak