first commit
This commit is contained in:
commit
a25b40574a
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
Algodat.iml
|
||||
target
|
24
pom.xml
Normal file
24
pom.xml
Normal file
@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>xyz.joethei.studium</groupId>
|
||||
<artifactId>algodat</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>8</source>
|
||||
<target>8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
|
||||
</project>
|
@ -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<Integer> list = new ArrayList<Integer>();
|
||||
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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user