DEV Community

Hyunjin Cho
Hyunjin Cho

Posted on

2 2

[Android Studio] Duplicate value

Three arrayList:
Two for ArrayList - will take information of movie
One for ArrayList - will take movie id of the movie

  1. Add all movie information object from database to reviewedArrayList(ArrayList)

  2. While looping the reviewedArrayList, check if the movieIDArrayList(ArrayList) contains the movie id. When it does not have it, add it to movieIDArrayList and add the information object containing the movie id to newList(ArrayList) and if not, skip it.

  3. Give newList which does not have duplicated value(movie id) to somewhere that I want to use.

  public void onDataChange(@NonNull DataSnapshot snapshot) {
                reviewedArrayList = new ArrayList<>();
                movieIDArrayList = new ArrayList<>();
                newList = new ArrayList<>();
                for(DataSnapshot childSnapshot: snapshot.getChildren()){
                    Playlist playlist = childSnapshot.getValue(Playlist.class);
                    reviewedArrayList.add(playlist);

                    for(int i=0; i < reviewedArrayList.size(); i++){
                        String mID = reviewedArrayList.get(i).mID;
                        if(!movieIDArrayList.contains(mID)){
                            movieIDArrayList.add(mID);
                            newList.add(reviewedArrayList.get(i));
                        }
                    }

                }
Enter fullscreen mode Exit fullscreen mode

Sentry mobile image

Mobile Vitals: A first step to Faster Apps

Slow startup times, UI hangs, and frozen frames frustrate users—but they’re also fixable. Mobile Vitals help you measure and understand these performance issues so you can optimize your app’s speed and responsiveness. Learn how to use them to reduce friction and improve user experience.

Read the guide →

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay