Given an array like the one below, I was wondering if there is an easy way to turn this array into an array with unique values only?
This is given:
numbers={5,5,4,3,1,4,5,4,5}
Turn it into a result array like this, preserving the original order:
{5,1,2,3,4}
In Java 8, use
IntStreamto get unique elements of an arrayThe simplest way would be to create set from the array.
and then you can retrieve the array using:
use LinkedHashSet if you want to maintain the order or TreeSet if you want to have it sorted.