Java Array Replace replaceChars(String s, char[] from, char[] to)

Here you can find the source of replaceChars(String s, char[] from, char[] to)

Description

replace Chars

License

Apache License

Declaration

public static String replaceChars(String s, char[] from, char[] to) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.Arrays;

public class Main {
    public static String replaceChars(String s, char[] from, char[] to) {
        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]);/*  www  . j a v  a2s .  c o  m*/
            } else {
                sb.append(ch);
            }
        }
        return sb.toString();
    }
}

Related

  1. replace(char[][] arrays, char character, char[][] replacements)
  2. replace(char[][] arrays, char character, char[][] replacements)
  3. replaceAll(final Object[] objs, final String str)
  4. replaceAll(final String[] args, final String from, final String to)
  5. replaceAll(String src, String[] replace, String[] by)
  6. replaceIgnoreCase(final String s, final String[] sub, final String[] with)
  7. replaceInArray(String[] thisArray, String findThis, String replaceWithThis)
  8. replaceWithValues(String subject, String needle, String[] values)