8:31 pm - Thursday April 27, 2017

Program for creating stringtokenizer using display boolean hasmoretokens() method

CANDID INDUSTRIAL TRAINING -- CHENNAI
Corporate Training for Experienced Candidate
Struts | Hibernate | Spring | Java / J2EE
SOAP | RestFull | Design Pattern | more...
Ph: +91 72000 69003
137b, 2nd st, shanthi nagar, Chrompet, Chennai -600044

BACK

Program for creating stringtokenizer using display hasmoretokens() method

Example Program


import java.util.StringTokenizer;

public class StringTokenizertt {

	public static void main(String[] args) {

		// creating stringtokenizer

		StringTokenizer st = new StringTokenizer("I love java program");

		// counting tokens

		System.out.println("Total tokens :" + st.countTokens());

		// checking tokens

		while (st.hasMoreTokens()) {

			System.out.println("Next tokens :" + st.nextToken());

		}

	}
}

 

Output

Total tokens :4

Next tokens :I

Next tokens :love

Next tokens :java

Next tokens :program

 

Explanation

public boolean hasMoreTokens()

Tests if there are more tokens available from this tokenizer’s string. If this method returns true, then a subsequent call to nextToken with no argument will successfully return a token.

Returns:

true if and only if there is at least one token in the string after the current position; false otherwise.

 

BACK

 

Filed in: Z-A All Java Codes

Comments are closed.