1

How to match string with ArrayList and check if is found or is not found I'm getting list of dates from json and save in ArrayList. How will I match ArrayList with string to check ArrayList contains string value or not?

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

2 Answers 2

2
if(!Vacation_Date.contains(jb.getString("date")))
{
  Vacation_Date.add(jb.getString("date"));
     //Do your stuff here .
}
Sign up to request clarification or add additional context in comments.

2 Comments

i mean check Vacation_Datearray list contain sampledate
@smartguy yes you can use arraylist.contain("valuetoCheck") for checking if arraylist contains that value or not, Please explain if im am wrong .
1

You can check by this:

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

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

  // do your stuff here
}

}

1 Comment

first you have to get your string from array list and then convert it to simple date format and after that compare the string with your date string

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.