Here you can find the source of arrayContains1(String[] parent, String[] child)
Parameter | Description |
---|---|
parent | a parameter |
child | a parameter |
private static boolean arrayContains1(String[] parent, String[] child)
//package com.java2s; //License from project: Apache License import java.util.Arrays; public class Main { /**//from ww w. j av a 2 s . c o m * test if all items in parent also appears in child * * @param parent * @param child * @return */ private static boolean arrayContains1(String[] parent, String[] child) { if (child.length == 0) { return true; } String[] parentCopy = Arrays.copyOf(parent, parent.length); String[] childCopy = Arrays.copyOf(child, child.length); Arrays.sort(parentCopy); Arrays.sort(childCopy); int i = 0, j = 0; while (i < parentCopy.length && j < childCopy.length) { if (childCopy[j].equals(parentCopy[i])) { i++; j++; } else { j++; } } if (i == parentCopy.length) { return true; } else { return false; } } }