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..

4

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

1

use

public static int frequency(Collection c, Object o)

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.