集册 Java实例教程 交集二数组

交集二数组

欢马劈雪     最近更新时间:2020-01-02 10:19:05

507
交集二数组


//package com.nowjava;
/*
来 自*
 时 代      J a v a   公   众 号 - nowjava.com
*/

import java.util.ArrayList;

import java.util.List;


public class Main {

    public static void main(String[] argv) {

        Object[] array1 = new String[] { "1", "abc", "level", null,

                "nowjava.com", "asdf 123" };

        Object[] array2 = new String[] { "1", "abc", "level", null,

                "nowjava.com", "asdf 123" };

        System.out.println(intersection(array1, array2));

    }


    static public List intersection(Object[] array1, Object[] array2) {/*时 代 J a v a 提 供*/

        ArrayList result = new ArrayList();

        if (array1 != null && array2 != null) {

            for (int i = 0; i < array1.length; i++) {

                Object o1 = array1[i];

                for (int j = 0; j < array2.leng
展开阅读全文