3

I have an arraylist in which i am storing a list of values. I have to check whether the list contains the same value more than once..And i need only the non-repeating values.. How can i check the number of existences of a value in array list??

Thanks in advance..

Sathish
  • 4,403
  • 7
  • 31
  • 53
Deepzz
  • 4,573
  • 1
  • 28
  • 52

2 Answers2

1

use

public static int frequency(Collection c, Object o)

to get frequency of an object in a collection(arraylist).

jeet
  • 29,001
  • 6
  • 52
  • 53
1

Here is how you can do it:

 ArrayList<String>numbers= new ArrayList<String>();

numbers.add("1");
numbers.add("2");
numbers.add("1");
numbers.add("3");


int count= Collections.frequency(numbers, "1");

In this way count returns 2.

AppMobiGurmeet
  • 719
  • 3
  • 6