aspose file tools*
The moose likes I/O and Streams and the fly likes How Can i filter the tokens Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "How Can i filter the tokens" Watch "How Can i filter the tokens" New topic
Author

How Can i filter the tokens

Moham'd
Greenhorn

Joined: May 06, 2005
Posts: 12
Hi guys,

I want to filter a stream of numbers or char or what ever,

for example,
i have a program that prompt the user to write 6 digits
>1 2 3 4 5 6
then the program will filter the digits that don't contain 3, which is1,2, 4,5 and 6

iam trying with this code, but it never succeed


while (token.hasMoreTokens())
{
if((token.nextToken())!="3")
System.out.println(token.nextToken());
else ...
...
}

in the above code
it will check if the digit is not 3, then it will print the digit after. NOT THE CURRENT DIGIT
*************************
the Question is:-
how can i print the current digit
is there a way?.
*****************************
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18896
    
  40

in the above code
it will check if the digit is not 3, then it will print the digit after. NOT THE CURRENT DIGIT
*************************
the Question is:-
how can i print the current digit
is there a way?.
*****************************


If you want to print the current digit, don't call nextToken() again. Use the token that you got in the "if" statement.

And BTW, you should be using the equals() method to compare the values of strings.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Moham'd
Greenhorn

Joined: May 06, 2005
Posts: 12
Originally posted by Henry Wong:


If you want to print the current digit, don't call nextToken() again. Use the token that you got in the "if" statement.

And BTW, you should be using the equals() method to compare the values of strings.

Henry


Thx Henry,
but this is my old question, How to print the token that i got from the if statement?.
there is no such method in StringTokenizer
What do you think about the Arrray??. Is it a possible solution?.

Regards
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18896
    
  40

Sometimes the most obvious solution is the correct solution. You are definitely "over thinking" the problem.

Henry


[ May 10, 2005: Message edited by: Henry Wong ]
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

Mr. Class --

This is the second time I'm asking you to please change your display name to comply with our naming policy. To refresh your memory, that policy states that your display name must be a real (sounding) first and last name. I know you've already had some questions answered on JavaRanch -- I don't think it's to much for us to ask in return that you follow a few simple rules. Please take care of this right away.


[Jess in Action][AskingGoodQuestions]
Moham'd
Greenhorn

Joined: May 06, 2005
Posts: 12
Originally posted by Ernest Friedman-Hill:
Mr. Class --

This is the second time I'm asking you to please change your display name to comply with our naming policy. To refresh your memory, that policy states that your display name must be a real (sounding) first and last name. I know you've already had some questions answered on JavaRanch -- I don't think it's to much for us to ask in return that you follow a few simple rules. Please take care of this right away.



I'm very sorry Mr.Ernest Friedman-Hill, this is my 1st time i see this complaint from you.

please accept my apology,

best Regards

[ May 10, 2005: Message edited by: Moham'd ]
[ May 10, 2005: Message edited by: Moham'd ]
Moham'd
Greenhorn

Joined: May 06, 2005
Posts: 12
Originally posted by Henry Wong:
Sometimes the most obvious solution is the correct solution. You are definitely "over thinking" the problem.

Henry



[ May 10, 2005: Message edited by: Henry Wong ]



Thank you Mr. Henry for your support, it is working fine with me

Best Regards
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How Can i filter the tokens