String Tokenizer
Hi Friends ,
I'm currently working on StringTokenizer class , I have used " , " as a deliminator and i wanted to check what StringTokenizer returns if it has only one token and how can i get that return value. Can i use this return value in if statement.
Waiting for your reply with example.
Thanks in advance.......................
Regards
- Pravin
[387 byte] By [
pravinmka] at [2007-11-27 2:55:44]

You can find information about that class in the [url=http://java.sun.com/j2se/1.4.2/docs/api/java/util/StringTokenizer.html]API documentation[/url].
If you encounter a problem with your code, then post it here along with relevant information (e.g. expected v.s. unexpected behaviour, error messages, stack trace, etc.)
String s ="ayberk";
StringTokenizer st = new StringTokenizer(s,",");
String ret = "";
while(st.hasMoreTokens())
{
ret = st.nextToken();
}
in this code there is only one token,and ret takes the value of this token which is "ayberk"
if you change the value of s="ayberk,cansever"
ret becomes cansever because it is assigned the last token since it is in while loop.you can store the tokens in an array or vector if it is needed.
ayberk cansever
now i recognized if clause wish,hmm
String s ="ayberk";
StringTokenizer st = new StringTokenizer(s,",");
String ret = "";
if(st.countTokens()==1)
{
ret=st.nextToken();
}
you can get it if count is 1.