From a25b40574a20f0c6cd544ffefbb27adb51c71341 Mon Sep 17 00:00:00 2001 From: Johannes Theiner Date: Fri, 2 Nov 2018 16:43:27 +0100 Subject: [PATCH] first commit --- .gitignore | 2 + pom.xml | 24 ++++++++++++ .../studium/algodat/DuplicatesList.java | 37 +++++++++++++++++++ 3 files changed, 63 insertions(+) create mode 100644 .gitignore create mode 100644 pom.xml create mode 100644 src/main/java/xyz/joethei/studium/algodat/DuplicatesList.java diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..308d4d9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +Algodat.iml +target \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..4ef10ea --- /dev/null +++ b/pom.xml @@ -0,0 +1,24 @@ + + + 4.0.0 + + xyz.joethei.studium + algodat + 1.0-SNAPSHOT + + + + org.apache.maven.plugins + maven-compiler-plugin + + 8 + 8 + + + + + + + \ No newline at end of file diff --git a/src/main/java/xyz/joethei/studium/algodat/DuplicatesList.java b/src/main/java/xyz/joethei/studium/algodat/DuplicatesList.java new file mode 100644 index 0000000..7da02c3 --- /dev/null +++ b/src/main/java/xyz/joethei/studium/algodat/DuplicatesList.java @@ -0,0 +1,37 @@ +package xyz.joethei.studium.algodat; + +import java.time.Instant; +import java.util.*; +import java.util.stream.Collectors; + +public class DuplicatesList { + + private static void duplicateDetection(List list) { + for (int i = 0; i < list.size(); i++) { + for (int j = 0; j < list.size(); j++) { + Object obj = list.get(j); + if (list.indexOf(obj) != list.lastIndexOf(obj)) { + list.remove(obj); + } + } + + } + } + + public static void main(String[] args) { + List list = new ArrayList(); + Random random = new Random(); + for (int i = 0; i < 10000; i++) { + list.add(random.nextInt(10)); + } + System.out.println(list); + long time = System.currentTimeMillis(); + duplicateDetection(list); + /* + Stream Variant + list = list.stream().distinct().collect(Collectors.toList()); + */ + System.out.println("time: " + (System.currentTimeMillis() - time)); + System.out.print(list); + } +} \ No newline at end of file