what is stringtolennizer with example?

Answer Posted / eva

The string tokenizer class allows an application to break a string into tokens

The set of delimiters (the characters that separate tokens) may be specified either at creation time or on a per-token basis.

An instance of StringTokenizer behaves in one of two ways, depending on whether it was created with the returnDelims flag having the value true or false:

If the flag is false, delimiter characters serve to separate tokens. A token is a maximal sequence of consecutive characters that are not delimiters.
If the flag is true, delimiter characters are themselves considered to be tokens. A token is thus either one delimiter character, or a maximal sequence of consecutive characters that are not delimiters.

Example:

StringTokenizer st = new StringTokenizer("this is a test");
while (st.hasMoreTokens()) {
System.out.println(st.nextToken());
}

prints the following output:

this
is
a
test

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is a lock or purpose of locks in java?

589


What is use of valueof () in java?

555


What is the difference between state-based unit testing and interaction-based unit testing?

493


What are advantages of using Java?s layout managers than windowing systems?

1853


Can we override private methods?

542






What is the most important feature of java? What is an interface?

512


What are wrapper classes in java?

594


Is array size fixed in java?

534


If a method is declared as protected, where may the method be accessed in java programming?

496


What is immutable in java?

539


Is string a data type in java?

590


What is the purpose of void class?

604


Write an algorithm program in java for the following question.. 1) S is a set of integers.X is an integer obtained by sum of two digits in S. Write logic for whether or not the X is from the S. The time of algorithm should not exceed o(n logn).

1602


How does multithreading take place on a computer with a single cpu in java programming?

527


What are the differences between getting and load method?

541