int a[] = {1,3};
int b[] = {1,3,5};
int size = a.length>b.length ?a.length:b.length;
int valueA =0 ;
int valueB =0;
for(int i =0;i<size;i++){
int tempA =1;
int tempB =1;
if(i<a.length){
valueA += tempA << a[i];
valueB += tempB << b[i];
} else {
valueB += tempB << b[i];
}
}
System.out.println(Integer.toBinaryString(valueA & valueB));
1010
3210
int b[] = {1,3,8,5};
int a[] = {1,3,4,5,8};
boolean flag = a.length>b.length ?true:false;
int size = a.length>b.length ?a.length:b.length;
Set<Integer> setInt = new HashSet<Integer>();
for (int i=0; i<size; i++){
if(!flag && i<a.length){
setInt.add(a[i]);
}
if(flag && i<b.length){
setInt.add(b[i]);
}
if(!flag &&setInt.contains(b[i])){
System.out.println(b[i]);
}
if(flag &&setInt.contains(a[i])){
System.out.println(a[i]);
}
}
}