下面这个方法 要求两个数组是已排序的 Java codepackage com.haojia.algorithm; /**  * 求两个已排序的数组的交集  *   * @author July  *   */ public class Intersect {     public static void go(int[] a, int[] b) {         int i = 0;         int j = 0;         while (i < a.length && j < b.length) {             if (a[i] < b[j]) {                 i++;             } else if (a[i] > b[j]) {                 j++;             } else {                 System.out.print(a[i] + " ");                 i++;                 j++;             }         }     }     public static void main(String[] args) {         int[] a = { 1, 5, 8, 10, 14, 15, 17, 18, 20, 22, 24, 25, 28 };         int[] b = { 2, 4, 6, 8, 10, 12 };         go(a, b);     } } ------解决方案-------------------- Java codeimport java.util.Arrays; import java.util.HashSet; import java.util.Random; import java.util.Set; public class SelectBag {     public static int find(int key,int[] N){         int lb=0;         int ub=N.length-1;         int in;         while(true){             in=(lb+ub)/2;             if(N[in]==key)                 return in;             else if(lb>ub)                 return -1;             else{                 if(N[in] list=new HashSet();         for(int m:M){             int getInt=find(m,N);             if(getInt!=-1)                 list.add(N[getInt]);         }         System.out.println("两个数组中重复的元素有:"+list);     }          public static int[] RandomIntArray(int count){         int[] array=new int[count];         Random r=new Random();         for(int i=0;i