Skip to content

Instantly share code, notes, and snippets.

@thiagotn
Created May 18, 2011 12:39
Show Gist options
  • Save thiagotn/978505 to your computer and use it in GitHub Desktop.
Save thiagotn/978505 to your computer and use it in GitHub Desktop.
Mescla Array
package testes;
import java.util.Arrays;
public class MesclaArrays {
public static void main(String[] args) {
int primeiro[] = {1,4,7,9,6};
int segundo[] = {2,3,5,8,10};
int terceiro[] = new int[primeiro.length + segundo.length];
// Copiando itens do primeiro array para o terceiro
System.arraycopy(primeiro, 0, terceiro, 0, primeiro.length);
// Copiando itens do segundo array para o terceiro
System.arraycopy(segundo, 0, terceiro, primeiro.length, segundo.length);
// Ordenando os itens do array
Arrays.sort(terceiro);
// Laço para imprimir itens do array
for (int i = 0; i < terceiro.length; i++) {
System.out.println(terceiro[i]);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment