How can you compare strings in android with greater than

前端 未结 2 1066
渐次进展
渐次进展 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.

提交回复
热议问题