code: public static <E> void swap(E[] x, E[] y) {
          if (x.length != y.length) {
              throw new IllegalArgumentException(String.format("Arrays have different length: x[%d], y[%d]", x.length, y.length));
          }
  
          for (int i = 0; i < x.length; i++) {
              E s = x[i];
              x[i] = y[i];
              y[i] = s;
          }
      }
docs: Swap two arrays.