0

im having great difficulties with this. I made a Gridview with a CalendarView which in each position has a date assigned.i iterate it with this code..

for (int n = 0; n < mnthlength; n++) {

        itemvalue = df.format(pmonthmaxset.getTime());
        Log.v("Calendar","look at this----->"+itemvalue);
        pmonthmaxset.add(GregorianCalendar.DATE, 1);
        day_string.add(itemvalue);

    }

i have another code for a method that returns another arraylist...

private List<ParseObject>getEventListFromParse(){

    ParseQuery<ParseObject> query = ParseQuery.getQuery("Event");
    query.whereEqualTo("Comercial", ParseUser.getCurrentUser().getObjectId());
    query.include("Fecha");

    query.findInBackground(new FindCallback<ParseObject>() {
        public void done(List<ParseObject> objects, ParseException e) {
            if (e == null) {
                for (ParseObject obj:objects
                ) {

                    eventArraylist=new ArrayList<>();
                    eventArraylist.add(obj);


                }
            } else {
                Log.d("score", "Error: " + e.getMessage());
            }
        }
    });
    return eventArraylist;
}

so we now have

List<String> day_string;

and

List<ParseObject> eventArraylist;

This both have elements presented like string yyyy-mm-dd. i need to the comparison to loop though each position starting from 0 and tell me if in the first element of day_string (For example is today 2019-03-20) if there is a matching date on the eventArraylist.

i checked some stack post but could implement them. How to compare two types of arraylist in android

Tom Fox
  • 897
  • 3
  • 14
  • 34
Felipe Franco
  • 171
  • 3
  • 15

1 Answers1

0

Looks like you are trying to compare a String with ParseObject object which is never going to fly. For sake of correctness you might want to consider storing Date in the lists or parse objects to Date before comparing.

When you do that since Date implements Comparable, its as easy as

date1.compareTo(date2);

Also you can iterate over day_string and check if element exists using

eventArraylist.contains(desiredElement)

Sushant
  • 440
  • 3
  • 8
  • Thank you for responce @Sushant but can you help me comparing the two list what if i have 1000000 of data in each list. – Felipe Franco Mar 21 '19 at 02:52
  • Hmm that was not your original question but nevertheless I will try to answer it, number of records, type of operation (read/write) and space constraint are main factor in determining the right data structure. ArrayList is still very compact compared to other alternatives. So you can continue to use ArrayList and perhaps sort the records using `Collection.sort(list)` and then search using utilities like `Collections.binarySearch(list, key)` . I don't think there is any problem storing 1 million records in an ArrayList as long as your JVM has enough memory. – Sushant Mar 21 '19 at 05:33
  • You may also want to look at Apache Common library for utilities to compare lists e.g , http://commons.apache.org/proper/commons-collections/javadocs/api-3.2.2/org/apache/commons/collections/CollectionUtils.html#intersection%28java.util.Collection,%20java.util.Collection%29 – Sushant Mar 21 '19 at 05:41
  • hi @Sushant can you please help me i was doing some research and i found i could compare two list doing a for loop inside another.But i dont know how to do it and what to display inside. – Felipe Franco yesterday Delete – Felipe Franco Mar 23 '19 at 17:16