You can do it in one line in java 7:
String[] unique = new HashSet<String>(Arrays.asList(array)).toArray(new String[0]);
and shorter and simpler in java 8:
String[] unique = Arrays.stream(array).distinct().toArray(String[]::new);
More Related Contents:
- What's the output of this code written in java?
- How to find size/length of an array without using library functions/variables [closed]
- how to replace display array list equals another array list values
- java programming homework 2015 [closed]
- Finding the max/min value in an array of primitives using Java
- Convert ArrayList to String[] array [duplicate]
- Can I pass an array as arguments to a method with variable arguments in Java?
- Convert an array of primitive longs into a List of Longs
- Generic array creation error
- Cannot create an array of LinkedLists in Java…?
- How to convert an int array to String with toString method in Java [duplicate]
- Variable length (Dynamic) Arrays in Java
- ArrayIndexOutOfBoundsException when iterating through all the elements of an array
- Error: Generic Array Creation [duplicate]
- Use of array of zero length
- How do I remove a specific element from a JSONArray?
- Why is array indexing in Java start with 0?
- Remove duplicates from integer array
- Clone method for Java arrays
- Flatten nested arrays in java
- Java Minimum and Maximum values in Array
- Generate Random Numbers in Array [duplicate]
- How can I create an array in Kotlin like in Java by just providing a size?
- Getting the length of two-dimensional array
- String to char array Java
- Java ArrayList how to add elements at the beginning
- Printing out a 2D array in matrix format
- Why does array indexing in Java start with 0?
- How to convert a Java String to an ASCII byte array?
- Converting an int array to a String array