Java List <?> Set Method

pac*_*uzz 1 java list arraylist

我试图更改List中某个值的值,但是我无法使用set方法找到一种方法.

List<?> row = rse.next();
index = row.indexOf("nyc");
row.set(index, "New York");
Run Code Online (Sandbox Code Playgroud)

所以我从结果集中获取一行结果到ArrayList中,我被迫这样做,所以我使用了一个ArrayList或一个数组.我必须使用List.

我知道值都是String,有没有办法在列表中找到"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)  
Run Code Online (Sandbox Code Playgroud)

Rob*_*ell 7

您的引用 List<?> 是通配符类型,List<String> 如果您知道列表是String的,则将其更改为 它应该可以使用.