Delete duplicate strings in string array
This will work
array = new HashSet<String>(Arrays.asList(array)).toArray(new String[0]);
or just use a HashSet
instead of an array.
Proposed solution does not keep the order of the elements. If you use Java 8 or higher and want to maintain the order you can use streams as follows:
array = Arrays.stream(array).distinct().toArray(String[]::new);
Full example: https://www.javacodeexamples.com/java-string-array-remove-duplicates-example/849