This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin for Android App Development and have Peter Sommerhoff on-line!
See this thread for details.
Win a copy of Kotlin for Android App Development this week in the Kotlin forum!
  • 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
  • Devaka Cooray
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

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: 23813
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: 23813
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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!