1

如何匹配字符串ArrayList并检查是否找到我从 json 获取日期列表并保存在ArrayList. 我将如何ArrayList与字符串匹配以检查是否ArrayList包含字符串值?

字符串采样日期;采样日期="26/5/2013";

    static ArrayList<String> Vacation_Date = new ArrayList<String>();



            JSONObject json3 = new JSONObject(str2);

        status = json3.getString("status");
        if (status.equals("1")) {

            JSONArray school = json3.getJSONArray("data");

            for (int k = 0; k < school.length(); k++) {
                JSONObject jb = (JSONObject) school.getJSONObject(k);
                Category_ID.add((long) k);

                Vacation_Date.add(jb.getString("date"));
                }

      if(Vacation_Date.equals(sampledate)
  {
      //dosomething   
         }





         idid like this  
            if(Vacation_Date.equals(mydate))

        //in debug mode vocation is this    [2013-09-29, 2013-09-25, 2013-10-05, 2013-09-27]

   //   String   mydate;
 value of mydate in debug mode     mydate=///2013-09-19=///2013-09-19
4

2 回答 2

2
if(!Vacation_Date.contains(jb.getString("date")))
{
  Vacation_Date.add(jb.getString("date"));
     //Do your stuff here .
}
于 2013-09-19T13:31:02.103 回答
1

您可以通过以下方式检查:

for(int=0; i<Vacation_Date.size();i++){

if(Vacation_Date.get(i).equalsIgnoreCase(sampledate)){

  // do your stuff here
}

}
于 2013-09-19T13:38:46.610 回答