如何检查字符串是否等于或大于某些东西?

时间:2016-04-10 13:29:24

标签: java android

我想检查strCurrentSpeed是否大于或等于" 10"。 我怎么做?我收到错误 - "运算符> =未定义参数类型String,int"我知道这是非常基本但我无法找到解决方法

public void updateSpeed(CLocation location)
{
float nCurrentSpeed = 0;

if( location!=null )
{
  location.setUseMetricUnits(this.useMetricUnits());
  nCurrentSpeed = location.getSpeed();
}

Formatter fmt = new Formatter(new StringBuilder());
fmt.format(Locale.US, "%5.1f", nCurrentSpeed);
String strCurrentSpeed = fmt.toString();
strCurrentSpeed = strCurrentSpeed.replace(' ', '0');

String strUnits = "miles/hour";
if (this.useMetricUnits())
{
  strUnits = "meters/second";
}

TextView txtCurrentSpeed = (TextView) this.findViewById(R.id.txtCurrentSpeed);
txtCurrentSpeed.setText(strCurrentSpeed + " " + strUnits);

  if (strCurrentSpeed >= 10){
  //do action
  }}

2 个答案:

答案 0 :(得分:-1)

您可以执行以下操作:

if (Integer.valueOf(strCurrentSpeed) >= 10) { //Whatever }

答案 1 :(得分:-2)

使用显式转换:

if(Integer.parseInt(strCurrentSpeed) >=10)
{
  // Do you stuff
}