Java Array Replace replace(char[][] arrays, char character, char[][] replacements)

Here you can find the source of replace(char[][] arrays, char character, char[][] replacements)

Description

replace

License

Open Source License

Declaration

public static char[][] replace(char[][] arrays, char character, char[][] replacements) 

Method Source Code

//package com.java2s;
/**/* w ww  .  j  av  a  2 s .  c  om*/
 * Aptana Studio
 * Copyright (c) 2005-2011 by Appcelerator, Inc. All Rights Reserved.
 * Licensed under the terms of the GNU Public License (GPL) v3 (with exceptions).
 * Please see the license.html included with this distribution for details.
 * Any modifications to this file must keep this entire header intact.
 */

import java.util.ArrayList;

import java.util.List;

public class Main {
    public static char[][] replace(char[][] arrays, char character, char[][] replacements) {
        List<char[]> list = new ArrayList<char[]>();
        for (char[] array : arrays) {
            String string = String.valueOf(array);
            if (string.indexOf(character) >= 0) {
                for (char[] replacement : replacements) {
                    list.add(string.replaceAll(String.valueOf(character), String.valueOf(replacement))
                            .toCharArray());
                }
            } else {
                list.add(array);
            }
        }
        return list.toArray(new char[list.size()][]);
    }
}

Related

  1. arrayReplace(String haystack, String[] search, String[] replacements)
  2. replace(char[] array, char[] toBeReplaced, char[] replacementChars)
  3. replace(char[][] arrays, char character, char[][] replacements)
  4. replaceAll(final Object[] objs, final String str)
  5. replaceAll(final String[] args, final String from, final String to)
  6. replaceAll(String src, String[] replace, String[] by)