The exercise is about performing the union of two character string arrays.
Ex:
A={"a","b","c"}
B={"a","e"}
AB={"a","b","c","e",null}
The size of the array for the union can be the sum of the size of the other arrays, so there can be values null
in the union.
The code that I have joins two Arrays but it does not return me null
if two values are repeated.
public class Union{
public static String[] union(String[] vec1, String[] vec2){
String[] vec3= new String[vec1.length+vec2.length];
int i=0;
for(i=0;i<vec1.length;i++){
vec3[i]=vec1[i];
}
for(int j=0;j<vec2.length;j++){
int n=0;
if (vec1[n]!=vec2[j]){
vec3[i]=vec2[j];
n++;
i++;
}
if(vec1[n] == vec2[j]){
vec3[i]=null;
n++;
i++;
}
}
return vec3;
}
}