Hi I need to convert a SortedSet> to an array of integers but not sure how to do it.
This is the SortedSet I want to convert:
private SortedSet<List<Integer>> coords;
and this is the get method I am using which shows as an error:
public List<Integer> getCoords() {
return Arrays.asList(coords);
}
If I want to do something like this, would I have to go through the entire SortedList and make a new int[] array and just put all the values inside it? Or is there a much nicer way? I thought Arrays.asList could do this but now I am confused!
Thanks for reading!
Arrays.asList()
will not flatten anything!What you want is this:
With Java 8, one example would be:
There are other, shorter examples (see other answers or comments to this answer) as well.