• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Frits Walraven
Bartenders:
  • Carey Brown
  • salvin francis
  • Claude Moore

How Can i filter the tokens  RSS feed

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?.
*****************************
 
author
Posts: 23830
140
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
 
Moham'd
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 23830
140
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
author and iconoclast
Posts: 24203
43
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Moham'd
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
 
I miss the old days when I would think up a sinister scheme for world domination and you would show a little emotional support. So just look at this tiny ad:
Create Edit Print & Convert PDF Using Free API with Java
https://coderanch.com/wiki/703735/Create-Convert-PDF-Free-Spire
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!