Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

comparing between two arraylists and remove extra element from there

how do I compare two arraylists?

I have a sdCoverList array and thumbnailList array.

02-04 11:05:05.210: I/System.out(4035): HASHED THUMBNAIL[-2122410790, 2043473787, 1914391068, 1785308349, 1656225630, 1527142911, 1398060192, 1268977473, 1139894754, 1010812035, 1242943301, 1113860582, 984777863, 855695144, 726612425, 597529706, 468446987, 339364268, 210281549]
02-04 11:05:05.210: I/System.out(4035): SD COVER LIST[-2122410790, 2043473787, 1914391068, 1785308349, 1268977473, 1656225630, 1527142911, 1139894754, 1398060192, 1010812035, 1242943301, 1113860582, 984777863, 855695144, 726612425, 597529706, 468446987, 339364268, 210281549, 717409028]

In my sd cover list, i have an extra value that i want to remove away but first i'd have to compare with thumbnailList array first. if both have the same elements, don't do anything but if theres an extra, remove it from sd card.

My array lists

for sdCoverList:

// CHECK DIRECTORY BEFORE DELETING THEM
            File strPath = new File(Environment.getExternalStorageDirectory() + folderName+"/Covers");
            File yourDir = new File(strPath, "");
            if(yourDir.length()!=0)
            for (File f : yourDir.listFiles()) {
                if (f.isFile())
                {
                    String name = f.getName();
                    sdCoverList.add(name);
                    //System.out.println(sdCoverList);
                }

for hashedthumbnail

for (int a=0;a<=thumbnailList.size()-1;a++)
        {
            String hashed = String.valueOf(thumbnailList.get(a).hashCode());
            Log.d("hashed",hashed);
            hashedThumbnail.add(hashed);
        }
like image 923
user1234555 Avatar asked Feb 01 '26 19:02

user1234555


1 Answers

List<String> sdCoverList = new ArrayList<String>();
sdCoverList.add("-2122410790");
sdCoverList.add("2043473787");
sdCoverList.add("717409028");

List<String> hashedThumbnail = new ArrayList<String>();
hashedThumbnail.add("-2122410790");
hashedThumbnail.add("2043473787");

System.out.println("sdCover List: " + sdCoverList);
System.out.println("hashedThumbnail List: " + hashedThumbnail);


List<String> temp = new ArrayList<String>();
temp.addAll(sdCoverList);
temp.removeAll(hashedThumbnail);

System.out.println("temp List: " + temp);

sdCoverList.removeAll(temp);

System.out.println("sdCover List: " + sdCoverList);

The output will be

sdCover List: [-2122410790, 2043473787, 717409028]
hashedThumbnail List: [-2122410790, 2043473787]
temp List: [717409028]
sdCover List: [-2122410790, 2043473787]
like image 135
Ram kiran Pachigolla Avatar answered Feb 03 '26 09:02

Ram kiran Pachigolla



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!