Question

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!

Was it helpful?

Solution

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

OTHER TIPS

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"]
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top