Invertir cualquier array en JAVA

El código invierte un array de tipo entero o int, para invertir otro tipo de array, solo debemos cambiar el tipo de retorno, el tipo del parámetro que recibe, y el tipo de la variable aux presente en la funcion.
public static int[] invArray(int[] n) {
    int aux;
    for (int i = 0; i < n.length / 2; i++) {
        aux = n[i];
        n[i] = n[n.length - 1 - i];
        n[n.length - 1 - i] = aux;
    }

    return n;
}

Comentarios

Publicar un comentario

Si tenéis alguna duda o sugerencia, no dudéis en comentar. ;)

Entradas populares de este blog

Autocompletado de codigo en Sublime Text

Compilar y ejecutar JAVA desde Notepad++

Compilar y ejecutar JAVA desde Sublime Text