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!

有帮助吗?

解决方案

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

其他提示

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"]
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top