public static void writeMatrix(double[][] matrix,String fileName,String headerLine){
  ArrayList<String> list=new ArrayList<String>();
  if (headerLine != null) {
    list.add(headerLine);
  }
  for (int i=0; i < matrix.length; i++) {
    String line="";
    for (int j=0; j < matrix[0].length - 1; j++) {
      line+=matrix[i][j];
      line+="\t";
    }
    line+=matrix[i][matrix[0].length - 1];
    list.add(line);
  }
  writeList(list,fileName);
}

public static void writeMatrix ( double [ ] [ ] matrix , String fileName , String headerLine ) { ArrayList < String > list = new ArrayList < String > ( ) ; if ( headerLine != null ) { list . add ( headerLine ) ; } for ( int i = 0 ; i < matrix . length ; i ++ ) { String line = "" ; for ( int j = 0 ; j < matrix [ 0 ] . length - 1 ; j ++ ) { line += matrix [ i ] [ j ] ; line += "\t" ; } line += matrix [ i ] [ matrix [ 0 ] . length - 1 ] ; list . add ( line ) ; } writeList ( list , fileName ) ; }
if headerline = null , then add no line at top of file . " \ n " is added at end of first line by this method . matrix [ numberofrows ] [ numberofcolumns ]
