Java Array Contain arrayContains(String[] parent, String[] child)

Here you can find the source of arrayContains(String[] parent, String[] child)

Description

test if all items in parent also appears in child child array will be sorted

License

Apache License

Parameter

Parameter Description
parent a parameter
child a parameter

Declaration

public static boolean arrayContains(String[] parent, String[] child) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.Arrays;

public class Main {
    /**//from  ww w . ja v  a  2 s  . co m
     * test if all items in parent also appears in child child array will be sorted
     * 
     * @param parent
     * @param child
     * @return
     */
    public static boolean arrayContains(String[] parent, String[] child) {
        if (parent == null || parent.length == 0) {
            return true;
        }

        Arrays.sort(child);
        for (String i : parent) {
            if (Arrays.binarySearch(child, i) < 0) {
                return false;
            }
        }
        return true;

    }
}

Related

  1. arrayContains(String[] arr, String sg, boolean ignoreCase)
  2. arrayContains(String[] array, String str)
  3. arrayContains(String[] array, String value)
  4. arrayContains(String[] array, String value)
  5. arrayContains(String[] array, String word)
  6. arrayContains(String[] pArray, String pItem)
  7. ArrayContains(String[][] arr, String s)
  8. arrayContains(T haystack[], T needle)
  9. arrayContains(T search, T[] array, boolean def)