Java Utililty Methods Array Replace

List of utility methods to do Array Replace

Description

The list of methods to do Array Replace are organized into topic(s).

Method

StringarrayReplace(String haystack, String[] search, String[] replacements)
array Replace
String toReturn = haystack;
for (int i = 0; i < search.length; i++) {
    toReturn = toReturn.replace(search[i], replacements[i]);
return toReturn;
char[]replace(char[] array, char[] toBeReplaced, char[] replacementChars)
replace
int max = array.length;
int replacedLength = toBeReplaced.length;
int replacementLength = replacementChars.length;
int[] starts = new int[5];
int occurrenceCount = 0;
if (!equals(toBeReplaced, replacementChars)) {
    next: for (int i = 0; i < max; i++) {
        int j = 0;
...
char[][]replace(char[][] arrays, char character, char[][] replacements)
replace
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()][]);
char[][]replace(char[][] arrays, char character, char[][] replacements)
replace
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()][]);
Object[]replaceAll(final Object[] objs, final String str)
Returns stripped value from the specified array of stuff
if (isEmpty(objs, false)) {
    return null;
List<Object> list = new ArrayList<Object>(Arrays.asList(trimArray(objs)));
list.removeAll(Collections.singletonList(str));
return list.toArray(new Object[list.size()]);
String[]replaceAll(final String[] args, final String from, final String to)
replace All
return Arrays.stream(args).map(arg -> from.equals(arg) ? to : arg).toArray(String[]::new);
StringreplaceAll(String src, String[] replace, String[] by)
Replaces all Strings in replace by the corresponding String in by, that is the ith String in replace is replaced by the ith String in by, in order.
for (int i = 0; i < replace.length; i++) {
    src = src.replace(replace[i], by[i]);
return src;
StringreplaceChars(String s, char[] from, char[] to)
replace Chars
StringBuilder sb = new StringBuilder();
for (int i = 0; i < s.length(); i++) {
    char ch = s.charAt(i);
    int index = Arrays.binarySearch(from, ch);
    if (index >= 0) {
        sb.append(to[index]);
    } else {
        sb.append(ch);
...
StringreplaceIgnoreCase(final String s, final String[] sub, final String[] with)
replace Ignore Case
if (sub.length != with.length || sub.length == 0) {
    return s;
int start = 0;
final StringBuilder buf = new StringBuilder(s.length());
while (true) {
    final int[] res = indexOfIgnoreCase(s, sub, start);
    if (res == null) {
...
String[]replaceInArray(String[] thisArray, String findThis, String replaceWithThis)
replace In Array
String[] outputArray = new String[thisArray.length];
for (int i = 0; i < thisArray.length; i++) {
    outputArray[i] = thisArray[i].replaceAll(findThis, replaceWithThis);
return outputArray;