如何将字符串与ArrayList
匹配,并检查是否找到或找不到我从json获取日期列表并保存在ArrayList
中。如何将ArrayList
与字符串匹配以检查ArrayList
是否包含字符串值?
string sampledate; sampledate = “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
答案 0 :(得分:2)
if(!Vacation_Date.contains(jb.getString("date")))
{
Vacation_Date.add(jb.getString("date"));
//Do your stuff here .
}
答案 1 :(得分:1)
您可以查看:
for(int=0; i<Vacation_Date.size();i++){
if(Vacation_Date.get(i).equalsIgnoreCase(sampledate)){
// do your stuff here
}
}