Skip to content

Instantly share code, notes, and snippets.

@faizakram
Created June 26, 2018 08:29
Show Gist options
  • Save faizakram/9c56f2e22c43417b79cee19a146fa7cf to your computer and use it in GitHub Desktop.
Save faizakram/9c56f2e22c43417b79cee19a146fa7cf to your computer and use it in GitHub Desktop.
Remove duplicate prime number in a list
/*
* Remove duplicate prime number in a list
*/
for (int i = 0; i < list.size(); i++) {
if (Collections.frequency(list, list.get(i)) > 1) {
final Integer number = list.get(i);
if(LongStream.range(2, (long) Math.ceil(Math.sqrt(number + 1))).noneMatch(x -> number % x == 0))
{
list.remove(i);
}
}
}
@faizakram
Copy link
Author

Hi guys,
please share your valuable feedback so, I can update my skills

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment