Remove Duplicates

less than 1 minute read

The code has been modified slightly and now uploaded to the site.

Question

<— Return Home

Main.java

import java.util.ArrayList;
import java.util.Scanner;
public class Main{
    public static void main(String[] args) {
        ArrayList<Integer> list = new ArrayList<Integer>();
        Scanner input = new Scanner(System.in);
        System.out.print("Enter 10 numbers: ");
        for (int i = 0; i < 10; i++){
            list.add(input.nextInt());
        }
        removeDuplicate(list);
    }

    public static void removeDuplicate(ArrayList<Integer> list){
        for (int i = 0; i < list.size(); i++){
            for (int j = i + 1; j < list.size(); j++){
                if (list.get(i) == list.get(j)){
                    list.remove(j);
                }
            }
        }
        System.out.println(list);
    }
}

<— Return Home