Java List Union union(final char[]... list)

Here you can find the source of union(final char[]... list)

Description

union

License

BSD License

Declaration

public static char[] union(final char[]... list) 

Method Source Code

//package com.java2s;
/**//from  ww  w.  j a v  a 2s .  c  o m
 * OWASP Enterprise Security API (ESAPI)
 * 
 * This file is part of the Open Web Application Security Project (OWASP)
 * Enterprise Security API (ESAPI) project. For details, please see
 * <a href="http://www.owasp.org/index.php/ESAPI">http://www.owasp.org/index.php/ESAPI</a>.
 *
 * Copyright (c) 2007 - The OWASP Foundation
 * 
 * The ESAPI is published by OWASP under the BSD license. You should read and accept the
 * LICENSE before you use, modify, and/or redistribute this software.
 * 
 * @author Jeff Williams <a href="http://www.aspectsecurity.com">Aspect Security</a>
 * @created 2007
 */

import java.util.Arrays;

public class Main {
    public static char[] union(final char[]... list) {
        StringBuilder sb = new StringBuilder();

        for (char[] characters : list) {
            for (int i = 0; i < list.length; i++) {
                if (!contains(sb, characters[i])) {
                    sb.append(list[i]);
                }
            }
        }

        char[] toReturn = new char[sb.length()];
        sb.getChars(0, sb.length(), toReturn, 0);
        Arrays.sort(toReturn);
        return toReturn;
    }

    private static boolean contains(final StringBuilder input, final char c) {
        for (int i = 0; i < input.length(); i++) {
            if (input.charAt(i) == c) {
                return true;
            }
        }
        return false;
    }
}

Related

  1. shallowUnionCol(Collection> values)
  2. union(final List list1, final List list2)
  3. union(final List list1, final List list2)
  4. union(final List list1, final List list2)
  5. union(final List list1, final List list2)