字符串变量在switch语句中不会更改。 JAVA

时间:2015-10-30 01:04:22

标签: java string switch-statement

我试图在switch语句中更改字符串变量,如下所示:

ArrayList<String> listOfWeightLocations = new ArrayList<String>();
String weight;
ArrayList.add(weight);


Switch (num) {
    case 1:
        weight = "This";
        break;
    case 2:
        weight = "Other.";
        break;
    default:
        weight = "Another Either."
        break;
}

System.out.println(String.valueOf(listOfWeightLocations.get(0));

但它永远不会改变价值观。它保持为空。

0 个答案:

没有答案