有两个有序整数集合a和b,写一个函数找出它们的交集?
package com.hunsun;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
public class CompareTwo {
public static void main(String[] args) {
int[] a = {2, 3, 4, 7, 8, 9, 100, 130, 150, 160};
int[] b = {4, 6, 7, 8, 9, 10, 100, 130, 140, 150};
int i=0,j=0;
ArrayList al=new ArrayList();
while(i<a.length&&(j<b.length)){
if(a[i]<b[j])
i++;
else if(a[i]>b[j])
j++;
else{
al.add(a[i]);
i++;j++;
}
}
System.out.println(al);
}
}