【发布时间】:2013-10-23 05:30:33
【问题描述】:
任何人都可以告诉我为什么下面的代码 sn-p 给出了找不到符号错误, 当给定数组列表名称时,应使用此 swap(),它将索引位置 1 的内容与位置 2 交换
干杯!
public static void swap(String swapArray, int location1, int location2) {
int tempswap1 = swapArray.get(location1);
int tempswap2 = swapArray.get(location2);
swapArray.set(location1)=tempswap2;
swapArray.set(location2)=tempswap1;
}
【问题讨论】:
-
swapArray不是ArrayList,而是String。在 Java 中,Strings 是不可变的(无法修改)。