1

i created a program for read a WEKA file (.arff) and do "Calinski-Harabasz"... The problem is, i created a Arraylist(myA) of ArrayList(values) from the data source of weka:

ArrayList<ArrayList<Double>> myA = new ArrayList();
for(int i=0;i< data.numAttributes();i++)
{
  ArrayList<Double> este = new ArrayList();
  double[] values = data.attributeToDoubleArray(i);
  for (int j = 0; j < values.length; j++)
     este.add(values[j]);
  myA.add(este);
 }

now I have some like this:

ArrayList (3-list) of ArrayList (9-values)
2,3,2,5,2,1,4,1,3 
2,4,3,5,2,1,4,5,2
0,0,0,1,1,1,1,2,2 

Can I convert this to array?? something like array of array???

double[][] myArray = {lis1,lis2,lis3}
double[] list1 = {2,3,2,5,2,1,4,1,3}
double[] list2 = {2,4,3,5,2,1,4,5,2}
double[] list3 = {0,0,0,1,1,1,1,2,2}

My method "Calinski-Harabasz" only works fine with arrays...

chiastic-security
  • 20,430
  • 4
  • 39
  • 67
wspiders
  • 13
  • 2
  • 1
    possible duplicate of [From Arraylist to Array](http://stackoverflow.com/questions/7969023/from-arraylist-to-array) – christopher Sep 19 '14 at 07:58
  • Unrelated to the question, but watch your [raw types](http://docs.oracle.com/javase/tutorial/java/generics/rawTypes.html). – Mena Sep 19 '14 at 08:13

1 Answers1

2

If you want an array, why do you construct an ArrayList, especially since your data object already gives you arrays apparently?

double[][] a = new double[data.numAttributes()][];
for (int i=0; i < data.numAttributes(); i++)
    a[i] = data.attributeToDoubleArray(i);
chiastic-security
  • 20,430
  • 4
  • 39
  • 67
OhleC
  • 2,821
  • 16
  • 29