Created
June 26, 2018 08:29
-
-
Save faizakram/9c56f2e22c43417b79cee19a146fa7cf to your computer and use it in GitHub Desktop.
Remove duplicate prime number in a list
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi guys,
please share your valuable feedback so, I can update my skills