Javatpoint Logo

how to find number of duplicate elements in a java arraylist using no logic

By: maejaa*** On: Fri Feb 24 09:27:23 IST 2017     Question Reputation0 Answer Reputation0 Quiz Belt Series Points0  0Blank User
I need a java program to find how many times do the duplicate elements occur in a java arraylist (collections class)
This is my current code and I want to continue this to count the number of times when the duplicate elements occur in the array list


import java.util.*;
public class NumberCount{

public static void main(String args[])
{
System.out.println("Enter how many elements have to be entered");
Scanner x= new Scanner(System.in);
int n=x.nextInt();

ArrayList<Integer> a= new ArrayList<Integer>();

for(int i=0;i<n;i++)
{
System.out.println("Enter your element");

Scanner y= new Scanner(System.in);
int k=y.nextInt();
a.add(k);
}

System.out.println("Elements: "+a);
}

}

}
Up0Down