How can you compare strings in android with greater than

前端 未结 2 1065
渐次进展
渐次进展 2021-01-15 09:57

I was wondering if there is a way to compare strings in android with greater than or >.

Lets say I have this:

String numbers = number.getText().toStr         


        
相关标签:
2条回答
  • 2021-01-15 10:28

    You'll need to convert the String to a number first. Something like this:

    int number = Integer.parseInt(number.getText().toString());
    if (number > 9)
    {
        output.setText("50");
    }
    

    If the String is not guaranteed to be a valid integer you'll have to handle NumberFormatException too.

    0 讨论(0)
  • 2021-01-15 10:31

    Is there a reason you can't use

    Integer.valueOf("9");
    
    0 讨论(0)
提交回复
热议问题