Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

What method to do like "between" in java? Pls help  RSS feed

 
jay lai
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In java, I want to check for range,

if str between 0-4999 then do A
if str between 5000- 9999 then do B
Can anyone please help, thanks

if the input is String or Numeric, then what method in java should I use Thank you in advance
 
Campbell Ritchie
Marshal
Posts: 55698
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look in the Integer class for methods which might parse a String to an int. That will get your String into an ordinary numeric value, which you can apply > and < operators to.
 
jay lai
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, it works with Integer.parseInt,
 
Garrett Rowe
Ranch Hand
Posts: 1296
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I created a small class for range validation.


I'm at work right now so this may not be exactly right, but I think you get the idea. As always, your mileage may vary.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!