How to convert string to operator in java

后端 未结 9 1657
情歌与酒
情歌与酒 2021-01-16 03:12

I want to convert some String to an operator like this:

int value = 1;
int valueToCompare = 3;
String operation = \"<\";

if (value operation         


        
9条回答
  •  伪装坚强ぢ
    2021-01-16 04:05

    You could try using a switch statement:

    switch(operation) {
        case "<" : //code here
            break;
        case ">" : //code here
            break;
        case "==" : //code here
            break;
    }
    

提交回复
热议问题