Pregunta

I was wondering what does the following function do for the following input:

String s=" HELLO!THIS IS A TEST.OK?";
StringTokenizer stk=StringTokenizer(s," .,?!");

And also, can anyone explain about this function too? Thanks!

¿Fue útil?

Solución

StringTokenizer is used to split String into tokens. It allows you to provide a set of delimiters during creation time.In your case, you are creating a StringTokenizer instance with delimiters (space,dot,comma,question mark,exclamation).this will split the input string by using any of the delimiters provided.Please read the java doc

Otros consejos

StringTokenizer breaks your string into several pieces depending on what you give as the second argument. It breaks the first string whenever any of the characters of the second string is found.

So for your case you will get these strings after tokenizing:

["HELLO", "THIS", "IS", "A", "TEST", "OK"]
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top