Hi,
I have an algorithm that using cluster centroids, searches through an array of doubles (see below) putting the values closest to the centroids in repective arrayLists.
For example (handtyped, not source code, because it works)
PHP Code:
double[] array {1,2,3,4,5,6,7,8,9,10}
double[] centroids {1,4,7}
Using Euclidean distance this creates the following three ArrayLists
PHP Code:
list1{1,2}
list2{3,4,5}
list3{6,7,8,9,10}
This all works fine, however could someone please help me to dynamically create arrayLists? Right now I'm actually instantiating three of them by hand, but in the working program the number of centroids will be dynamic so the program will need to create as many as required. I was thinking a 2D array, but not really sure if that is the best way to go about this.
I'm really stuck on this, any help would be hugely appreciated