Get the App
SLTechnology News&Howtos  ›  Development  › 

What are the common methods of StringTokenizer class in Java

Shulou Source: shulou.com Published: 2022-06-03 11:01:13 11月15日 Update

Editor to share with you what are the common methods of the StringTokenizer class in Java, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

JavaStringTokenizer belongs to the java.util package and is used to separate strings.

StringTokenizer construction method:

1.StringTokenizer (Stringstr): construct a StringTokenizer object to parse str. The default delimiters for java are spaces (""), tabs (\ t), line feeds (\ n), and carriage returns (\ r).

2.StringTokenizer (Stringstr,Stringdelim): constructs a StringTokenizer object to parse str and provides a specified delimiter.

3.StringTokenizer (Stringstr,Stringdelim,booleanreturnDelims): constructs a StringTokenizer object to parse the str, provides a specified delimiter, and specifies whether the delimiter is returned.

Common methods of StringTokenizer:

1.intcountTokens (): returns the number of times the nextToken method was called.

2.booleanhasMoreTokens (): returns whether there is a delimiter.

3.booleanhasMoreElements (): returns whether there is a delimiter.

4.StringnextToken (): returns a string from the current position to the next delimiter.

5.ObjectnextElement (): returns a string from the current position to the next delimiter.

6.StringnextToken (Stringdelim): similar to 4, the result is returned with the specified delimiter.

These are all the contents of this article entitled "what are the common methods of StringTokenizer classes in Java?" Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Delimiters methods commonly used characters strings objects articles locations content not much tabs at the same time most newline characters more times knowledge spaces results industry Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker Redmi Linux MariaDB Microsoft