2016-06-08 49 views
2

我想使用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")); 

(首选项正常工作)

+0

尝试在将日期添加到列表和使用索引时修剪日期。 '(preferences.getString(“auswahldatum”,“n”)。trim())'可能是一些额外的空间导致它找不到索引。 – Vucko

+0

谢谢你的回答,但它没有帮助:( –

+1

@Vucko,可能是这样,但在这种情况下他不会得到-1?0表示匹配在第一个元素上找到,并假设这些示例是正确的,那是完全错误的...... –

回答

3

这实际上是应该的。您正在对ArrayList进行排序,值1467590400(它们中的最小者)在新排序列表中占据第一个位置(,0索引)。

+0

总之,这个lis你在你的问题中没有适当的排序。 – zgc7009

+0

基本上。但我认为他在排序前显示清单。 – Vucko