我正在尝试更改列表中某个值的值,但我无法使用 set 方法找到执行此操作的方法。
List<?> row = rse.next();
index = row.indexOf("nyc");
row.set(index, "New York");
所以我从结果集中获取一行结果到 ArrayList 中,我被迫这样做所以我使用 ArrayList 或数组。我必须使用列表。
我知道这些值都是字符串,有没有办法在列表中找到“nyc”,并将其替换为“New York”。目前上面的代码给出了这个错误:
The method set(int, capture#4-of ?) in the type List<capture#4-of ?> is not
applicable for the arguments (int, String)
最佳答案
您的引用
List<?>
是通配符类型,改成
List<String>
如果您知道该列表是 String 的并且它应该可以工作。
关于Java List<?> 设置方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17113141/