I have two arrays
int arr1 [] = {4, 6, 2, 6, 4, 8, 12, 14, 18, 4, 38};
int arr2 [] = {4, 2, 8, 6, 18, 12};
arr1 contains every value of arr1, sometimes multiple.
arr2 contains every value only once.
The order of the elements in arr1 should be the same as the order of the elements in arr2.
Elements that are in arr1 but not in arr2 should be appended to the end in the same order.
This is how they should look in the end:
new arr1[] = {4, 4, 4, 2, 8, 6, 6, 18, 12, 14, 38};
Here´s what I tried:
int [] temp = new int [arr1.length];
for (int i = 0; i<arr.length; i++){
if (arr2[i] == arr1[i]){
temp[arr2[i]] == arr1[i];
}
}
for (int k = 0; k<arr1.length; k++){
arr1[k] == temp[k];
arr2[k] == k;
}