Free Response Question 1: Removing Duplicates From an ArrayList

In this exercise, you'll remove duplicates from an ArrayList type object.

We'll cover the following

Background

Suppose we have a bucket of colorful balls. Your task is to make sure that no ball of the same color is repeated. For example, if there are:

  • 2 red balls: đź”´, đź”´
  • 2 green balls: 🟢, 🟢
  • 1 blue ball: 🔵

You have to remove one red ball and one green ball from the bucket. The task is simple. Suppose we have a bucket full of one hundred balls. You’re not allowed to empty the bucket, pick each color, and put it back in the bucket. You’re only allowed to remove the duplicates. It’s a little tricky.

In this challenge, you’re required to remove the duplicate colors from the bucket (ArrayList) via a Java program.

Problem statement

Intent: Write a removeDuplicates() function that takes an ArrayList and removes the duplicates from it.

  • Declare the header of the removeDuplicates() method properly.

Get hands-on with 1400+ tech skills courses.