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]
# 1

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.)

TimTheEnchantora at 2007-7-12 3:32:45 > top of Java-index,Java Essentials,Java Programming...
# 2

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.

ayberka at 2007-7-12 3:32:45 > top of Java-index,Java Essentials,Java Programming...
# 3
Thanks friend....................
pravinmka at 2007-7-12 3:32:45 > top of Java-index,Java Essentials,Java Programming...