Kr Neki :
I have to convert an ArrayList of ArrayList in to Array.
List<List<TockaXY>> clustersPorazdeljeni = new ArrayList<>(centers.size());
I know that is possible to convert a single ArrayList to Array like
TockaXY[] arrayOfClusters = clustersPorazdeljeni.toArray(new TockaXY[centers.size()]);
But these does not convert the nested part. As i understand is now array of ArrayLists. So is it possible to get an Array out of nested ArrayLists?
Jackkobec :
There is linear alternative for flatMap():
List<List<TockaXY>> clustersPorazdeljeni = new ArrayList<>();
List<TockaXY> flatArray = new ArrayList<>();
clustersPorazdeljeni.forEach(flatArray::addAll);
TockaXY[] arrayOfClusters = flatArray.toArray(new TockaXY[0]);
Or with flatMap:
TockaXY[] arrayOfClusters = clustersPorazdeljeni.stream().flatMap(Collection::stream).toArray(TockaXY[]::new);