0

Here is my code:

if(Rs.getInt("Number") == 100){
 //Do something
}

Rs is a PreparedStatement.

Instead of defining the exact number, I want to look for numbers which start with 1. Maybe there are '110' or '120' ... what should i write in the loop instead of the operator == ?

  • 1
    `Rs.getString("Number").startsWith("1")` :O – Adrian Colomitchi Dec 07 '16 at 01:19
  • Thank you for your reply. Otherwise i would accept your first suggestion if you could modify your answer,since i want to select as well the values that start with 2 separately,then all values start with 3 and so on .. – user5953665 Dec 07 '16 at 01:24
  • Mate, look over the [String.startsWith](https://docs.oracle.com/javase/7/docs/api/java/lang/String.html#startsWith(java.lang.String)) method and use it with what prefixes you wish. – Adrian Colomitchi Dec 07 '16 at 01:29

1 Answers1

0

This guy here seems to have the right idea.

Retrieving the first digit of a number

if ("1".equals(Integer.parseInt(Rs.getInt(number).substring(0, 1)))){
//do stuff
}
Community
  • 1
  • 1
Josh
  • 115
  • 1
  • 15
  • OK, I'll flag as a duplicate. – Nissa Dec 07 '16 at 02:02
  • Did that work for you? – Josh Dec 07 '16 at 02:15
  • i think it s not the same request ! As i wanted to select all the records which started with 1. For example if i have 110 ,199,13123,1424. It should retrieve them all as they start with 1.Thanks – user5953665 Dec 07 '16 at 02:35
  • @user5953665 no, I'm afraid it's a duplicate. Retrieving the first digit of the number allows you to branch off if it's a 1. You can't ask for code personally tailored to your own situation. – Nissa Dec 07 '16 at 21:39