w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Check if Character-array contains all elements in a smaller Character-array in Java

Use Set:

public static boolean allContained(char[] big, char[] small) {
    Set<Character> chars = new HashSet<>(big.length);
    for(char c : big) {
        chars.add(c);
    }
    for(char c : small) {
        if(!chars.contains(c)) {
            return false;   // small contains elements that are not in big
        }
    }
    return true;
}




© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.