我想使用indexOf(),但它不能正常工作。indexOf() - 列表 - Android - 不应该像它应该
List<String> datume = new ArrayList<>();
for(int i = 0; i < datumes.length(); i++){
datume.add(datumes.getJSONObject(i).getString("Datum"));
}
java.util.Collections.sort(datume);
它看起来像这样:
[1468281600, 1468195200, 1468022400, 1467936000, 1467849600, 1467763200, 1467676800, 1467590400, 1468368000, 1468454400, 1468540800]
但每次它只返回0,当我搜索此:
1467590400
与...
pos = datume.indexOf(preferences.getString("auswahldatum", "n"));
(首选项正常工作)
尝试在将日期添加到列表和使用索引时修剪日期。 '(preferences.getString(“auswahldatum”,“n”)。trim())'可能是一些额外的空间导致它找不到索引。 – Vucko
谢谢你的回答,但它没有帮助:( –
@Vucko,可能是这样,但在这种情况下他不会得到-1?0表示匹配在第一个元素上找到,并假设这些示例是正确的,那是完全错误的...... –