code: private static CoordinateArraySequence convertSequence(Coordinate[] cs,int dimension) {        
          for (int i = 0; i < cs.length; i++) { 
              Coordinate coord = cs[i];
              switch (dimension) {
                  case 2:
                      coord.z = Double.NaN;
                      cs[i]=coord;
                      break;
                  case 3: {
                      double z = coord.z;
                      if (Double.isNaN(z)) {
                          coord.z = 0;
                          cs[i]=coord;
                      }
                      break;
                  }                
                  default:
                      break;
              }
          }        
          return new CoordinateArraySequence(cs, dimension);        
      }
docs: Create a new CoordinateArraySequence and update its dimension
  
  @param cs a coordinate array
  @return a new CoordinateArraySequence