How to get unique values from array

Solution 1:

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);

Solution 2:

HashSet will do the job.

You can try this:

List<String> newList = new ArrayList<String>(new HashSet<String>(oldList));