Java Arrays.asList(columnes).contains()返回false

时间:2015-04-25 05:59:57

标签: java android arraylist

在我的应用程序中,我有columnes变量,其中包含一些数据:

enter image description here

List<String> columnes = getSingleColumn("id");

现在我正在尝试将单个字符串检查到此数组中:

Arrays.asList(columnes).contains("1")

此检查总是返回false

我的完整代码:

    List<String> columnes = getSingleColumn("id");
    for (int i = 0; i < jsonArray.length(); i++) {
        JSONObject item = jsonArray.getJSONObject(i);

        cList = new Categories();
        cList.id = Integer.parseInt(item.getString(SV.FIELD_CATEGORY_ID));
        cList.title = item.getString(SV.FIELD_CATEGORY_TITLE);
        cList.followers = item.getString(SV.FIELD_CATEGORY_FOLLOWERS);
        cList.type = item.getString(SV.FIELD_CATEGORY_TYPE);
        cList.date = item.getString(SV.FIELD_CATEGORY_DATE);
        cList.imageUrl = item.getString(SV.FIELD_CATEGORY_IMAGE_URL);

        Log.e("Check : ", Arrays.asList(columnes).contains(cList.id+""));

} catch (JSONException e) {

}

1 个答案:

答案 0 :(得分:1)

Arrays.asList(list)返回List<List<String>>而非List<String>因此包含方法无法在列表列表中找到您的字符串(来自@TAsk的answer)。因此更改

Log.e("Check : ", Arrays.asList(columnes).contains(cList.id+""));

Log.e("Check : ", columnes.contains(String.valueOf(cList.id)));

并检查cList.id的值为

Log.e("cList id value: ", String.valueOf(cList.id));